0
我在BASH腳本下執行某些文件時遇到問題。如何從另一個腳本內執行腳本?
我想要的是,在運行SCRIPT.SH時,檢查它運行的目錄是否是正確的。在這種情況下,它是/ ROOT/OPENSOURCE。如果不是,則詢問用戶是否想將目錄移動到正確的位置。通過另一個腳本/OPENSOURCE/MODULES/MOVE.SH執行此操作。
我有這個變量拿到劇本推出DIR:
spath="$(cd "$(dirname $0)" && pwd)"
現在,因爲該腳本將不正確的目錄進行安裝,我需要運行MOVE.SH這是在內部OPENSOURCE模塊目錄。我無法完成這件事。
代碼:
# check if script is on correct directory
if [ "$rpath" = "$spath" ]; then
Colors;
echo ${RedF}[x] [WAIT]${YellowF} Checking directory: ${Reset};
sleep 1
echo ${BlueF}[*] [Directory]:${GreenF} OK ${Reset};
else
Colors;
echo ${RedF}[x] [WAIT]${YellowF} Checking directory: ${Reset};
sleep 1
echo ${BlueF}[*] [Directory]:${RedF} FAILED: This may cause a script malfunction ${Reset};
read -p "[!] Move script directory to right directory {y|n}:" pass
if test "$pass" = "y"
then
echo ${BlueF}[*] [Directory]: ${GreenF}Ok. Moving script to new directory${Reset};
sleep 1
---- COMMAND WILL BE HERE ----
else
echo ${BlueF}[*] [Directory]: ${YellowF}Ok not moving ${Reset};
fi
fi
我該怎麼辦呢?
不是我一直在尋找,但我已經修好了;) –