全部博文(362)
分类:
2010-10-04 15:55:12
一些脚本可能会依赖于使用不同的调用名字, 来表现出不同的行为. 如果想要达到这种目的, 一般都需要在脚本中检查$0
.
因为脚本只能够有一个真正的文件名, 如果要产生多个名字, 必须使用符号链接.
#!/bin/bash # hello.sh: Saying "hello" or "goodbye" #+ depending on how script is invoked. # Make a link in current working directory ($PWD) to this script: # ln -s hello.sh goodbye # Now, try invoking this script both ways: # ./hello.sh # ./goodbye HELLO_CALL=65 GOODBYE_CALL=66 if [ $0 = "./goodbye" ] then echo "Good-bye!" # Some other goodbye-type commands, as appropriate. exit $GOODBYE_CALL fi echo "Hello!" # Some other hello-type commands, as appropriate. exit $HELLO_CALL