$0扩展为
shell脚本的名称.
$cat ./sample-script #!/bin/bash echo $0 $chmod 700 ./sample-script $./sample-script ./sample-script
$ln -s ./sample-script symlinked-script $./symlinked-script ./symlinked-script
我怎么能得到别名的名字?这里`$0’再次扩展到文件名:
$alias aliased-script=./sample-script $aliased-script ./sample-script
我想你已经知道了这一点,但是为了记录,答案是:你需要通过实现别名的代码进行合作.
alternate_name () { MY_ALIAS_WAS=alternate_name real_name "$@" }
或者,如果您确实想使用被取代的别名语法:
alias alternate_name="MY_ALIAS_WAS=alternate_name real_name"
…然后…
$cat ~/bin/real_name #!/bin/sh echo $0,I was $MY_ALIAS_WAS,"$@"