可以在KornShell中获得当前脚本的绝对路径吗?

前端之家收集整理的这篇文章主要介绍了可以在KornShell中获得当前脚本的绝对路径吗?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
是否可以找到当前在KornShell(ksh)中执行的脚本的完整路径? @H_301_1@即如果我的脚本在/opt/scripts/myscript.ksh中,我可以在该脚本中以编程方式发现/opt/scripts/myscript.ksh?

@H_301_1@谢谢,

你可以使用:
  1. ## __SCRIPTNAME - name of the script without the path
  2. ##
  3. typeset -r __SCRIPTNAME="${0##*/}"
  4.  
  5. ## __SCRIPTDIR - path of the script (as entered by the user!)
  6. ##
  7. __SCRIPTDIR="${0%/*}"
  8.  
  9. ## __REAL_SCRIPTDIR - path of the script (real path,maybe a link)
  10. ##
  11. __REAL_SCRIPTDIR=$( cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P )

猜你在找的Bash相关文章