
if(-f runme ) then
cd `dirname $(find . -iname 'runme')`
chmod +x runme
source runme
cd -
CSH 腳本中是這樣嗎?
首先,它將在整個子目錄中遞歸搜尋 runme 文件,如果存在,那麼將轉到該文件所在的子目錄?
這就是問題——我的邏輯在語法上正確嗎?我認為當前的程式碼將在當前目錄中搜尋 runme 檔案。
我找到了解決方案,所以我想在下面分享。我在評論區也提到過。
find . -name "runme" > find_runme.txt
# Just below line used to remove the file name i.e runme here from "find path", and returns only directory path.
set a = `cat find_runme.txt | sed 's/\(.*\/\).*/\1/g'`
if (-z find_runme.txt) then
cd .
else
cd $a
endif
if(-f runme ) then
# cd `dirname $(find . -iname 'runme')`
chmod +x runme
setenv PATH /dv/project/agile/xcelium/test/install/install/tools.lnx86/bin:$PATH
source runme
cd -
答案1
csh
在本世紀沒有充分的理由使用它。
不過,在這裡我會這樣做:
find . -name runme -type f -execdir chmod +x '{}' ';' -execdir '{}' ';'
csh
即使假設您find
支援-execdir
BSD 擴充(現在很常見),它也可以在任何 shell 中運作。
那執行文件runme
,但它不在source
目前 shell 實例中。無論如何,source
ing 不需要執行權限。
無論如何,不,您的程式碼不是有效的 csh 語法。但是,如果您還不知道 csh 語法,那麼好消息是您不需要學習它,因為至少 3 年來人們就知道 csh 中的腳本是有害的,不應該這樣做,所以沒有人應該這樣做期待你這樣做。
如果您確實發現自己需要csh 腳本中的 cshsource
文件runme
,而當前工作目錄暫時是該文件的父目錄,則程式碼看起來更像是:
foreach file ("`find . -name runme -type f`")
cd $file:h:q || continue
source $file:t:q
cd - || break
end
runme
但請注意,如果路徑中包含換行符的文件,它將不起作用。