是否可以找到当前在KornShell(ksh)中执行的脚本的完整路径?
@H_301_1@即如果我的脚本在/opt/scripts/myscript.ksh中,我可以在该脚本中以编程方式发现/opt/scripts/myscript.ksh?
@H_301_1@谢谢,
你可以使用:
- ## __SCRIPTNAME - name of the script without the path
- ##
- typeset -r __SCRIPTNAME="${0##*/}"
- ## __SCRIPTDIR - path of the script (as entered by the user!)
- ##
- __SCRIPTDIR="${0%/*}"
- ## __REAL_SCRIPTDIR - path of the script (real path,maybe a link)
- ##
- __REAL_SCRIPTDIR=$( cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P )