我可以在KornShell中获取当前脚本的绝对路径吗? [英] Can I get the absolute path to the current script in KornShell?

查看:60
本文介绍了我可以在KornShell中获取当前脚本的绝对路径吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以找到KornShell(ksh)中当前正在执行的脚本的完整路径?

Is it possible to find out the full path to the script that is currently executing in KornShell (ksh)?

即如果我的脚本在/opt/scripts/myscript.ksh中,我可以在该脚本中以编程方式发现/opt/scripts/myscript.ksh吗?

i.e. if my script is in /opt/scripts/myscript.ksh, can I programmatically inside that script discover /opt/scripts/myscript.ksh ?

谢谢

推荐答案

您可以使用:

## __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 )

这篇关于我可以在KornShell中获取当前脚本的绝对路径吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆