Jan 25, 2010
给shell脚本传递变量
我们在运行程序的时候,经常遇到给它定义一个变量的情况,比如
-D -v。当然,不同的项目可能不同。但shell程序,如何给它传递一些
自定义的变量呢?
比如有如下代码:
#!/bin/shell
#file test.sh
if [ -z ${PARAM1} ]; then
PARAM1=test1
fi
echo ${PARAM1}
#end shell
test1为我们为test.sh设置的默认变量值,如果运行sh test.sh
那么输出为:
test1
如果我们想给其传一个参数为test2,那么该如何实现呢?
实际很简单:
PARAM1=hello sh test.sh
那么输出就是hello了,简单吧!
详细的判断条件文章请参考:shell常用条件判断
多谢
张久安
If you enjoyed this post, make sure you subscribe to my RSS feed!









No Comments, Comment or Ping
Reply to “给shell脚本传递变量”
You must be logged in to post a comment.