我試圖在我的主腳本的一個if條件中呼叫一個外部bash腳本。 外部腳本的代碼是IsArchive:
STR="$1"
if [[ "$STR" == *" .zip"* ]] || [[ "$STR" == *" .iso"* ]] || [[ "$STR" == *".tar.gxz"/span>* ]] || [[ "$STR" == *" .tar.gx"* ]] || [[ "$STR" == *" .tar.bz2"* ]] ||
[[ "$STR" == *".tar.gz"* ]] 。|| [[ "$STR" == *" .tar.xz"* ]] || [[ "$STR" == *" .tgz"* ]] || [[ "$STR" == *".tbz2"/span>* ]]
then
return 0
else
回傳 1
fi
我試著在我的主腳本中呼叫它:
elif [[ $Option = "2" ]
然后
if IsArchive "$SourcePath"/span>;
then
less -1Ras "$SourcePath"| tee "$OutputFilePath"。
#if file is not an archive""。
else
ls -1Rasl "$SourcePath"/span> | tee "$OutputFilePath"/span>
fi"。
當我執行主腳本的時候,我收到了錯誤。./script: line 61: IsArchive: command not found
uj5u.com熱心網友回復:
你只需要確保該腳本在你的PATH中。 或者,用全路徑或相對路徑來參考它。 也許你只需要寫:
if ./IsArchive "$SourcePath"/span>; then ...
但是IsArchive有幾個問題。你不能return,除了從一個函式中,所以你可能想使用exit 0和exit 1而不是return。 你可能不想把像foo.zipadeedoodah這樣的名字看作是一個歸檔檔案,但*".zip "*將與之匹配,所以你可能應該洗掉尾部的*。 用case陳述句來寫會更簡單:
#!/bin/bash
case "$1"/span> in
*.zip|*.iso|*.tar.gxz|*.tar.gx|*.tar.bz2|*.
*.tar.gz|*.tar.xz|*.tgz|*.tbz2) exit 0; 。
*) exit 1;;
esac
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/314508.html
標籤:
