在bash shell中,我可以得到一個即使腳本是由源,鏈接,調用的腳本的完整路徑/ ...等 這些神奇的bash行:TCSH腳本完整路徑
#Next lines just find the path of the file.
#Works for all scenarios including:
#when called via multiple soft links.
#when script called by command "source" aka . (dot) operator.
#when arg $0 is modified from caller.
#"./script" "/full/path/to/script" "/some/path/../../another/path/script" "./some/folder/script"
#SCRIPT_PATH is given in full path, no matter how it is called.
#Just make sure you locate this at start of the script.
SCRIPT_PATH="${BASH_SOURCE[0]}";
if [ -h "${SCRIPT_PATH}" ]; then
while [ -h "${SCRIPT_PATH}" ]; do SCRIPT_PATH=`readlink "${SCRIPT_PATH}"`; done
fi
pushd `dirname ${SCRIPT_PATH}` > /dev/null
SCRIPT_PATH=`pwd`;
popd > /dev/null
如何在TCSH shell中的相同條件下獲得腳本路徑?這些'魔術線'是什麼?
P.S.它不是this和類似問題的重複。我知道$0
。
[如果您可以避免腳本在tcsh中,您應該。](http://www.grymoire.com/Unix/CshTop10.txt) – Johnsyweb
我絕對同意你的看法。但我的目標是讓用戶的生活儘可能簡單。如果他們可以從任何地方運行「source environment.csh」,他們很容易。 TCSH需求是因爲RHEL 6將其用作用戶的默認外殼。 – MajesticRa
如果您使用tsch僅僅是因爲它是默認的shell,爲什麼不更改默認的shell呢? – carlpett