Can I get the absolute path to the current script in KornShell?

前端 未结 12 696
粉色の甜心
粉色の甜心 2020-12-29 06:26

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

i.e. if my script is in /opt/scripts/myscript.ksh

12条回答
  •  时光取名叫无心
    2020-12-29 06:45

    Well it took me a while but this one is so simple it screams.

    _SCRIPTDIR=$(cd $(dirname $0);echo $PWD)
    

    since the CD operates in the spawned shell with $() it doesn't affect the current script.

提交回复
热议问题