开发者

Problem getting full path of a shell script while using TCSH

I am using tcsh and I am trying to get path o开发者_StackOverflow社区f current shell script without success.

My script contains:

echo $0

source tmp.csh returns

/usr/lbin/tcsh

dirname $0

returns /usr/lbin


Use $_ (save it in a variable as the first thing the script does) instead of $0.

#!/bin/tcsh
set called=($_)
if ("$called" != "") then
    echo "sourced $called[2]"    # the script was sourced from this location
endif
if ("$0" != "tcsh") then
    echo "run $0"                # the script was run from this location
endif

Edit:

Perhaps in your .cshrc:

set basepath=/path/to/base
source "$basepath/scriptname" "$basepath"

and in your base script:

source "$1/subscript"

Unless the base script is in your $PATH, in which case you're just making things difficult on yourself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜