分页: 1 / 1
Re: 请问一下bash命令行参数
发表于 : 2010-09-05 16:50
由 ChenFengyuan
代码: 全选
$ cat test.sh
a=$(cat);echo $a
$echo "hello world"|bash test.sh
hello world
Re: 请问一下bash命令行参数
发表于 : 2010-09-05 16:53
由 ChenFengyuan
read a;echo $a
还是用read比较smart
太复杂的可以上perl,lol
Re: 请问一下bash命令行参数
发表于 : 2010-09-05 16:55
由 ChenFengyuan
Re: 请问一下bash命令行参数
发表于 : 2010-09-05 17:03
由 ChenFengyuan
我觉的是把数据放在stdin里了么,然后用个方法获取stdin即可,所以用$(cat)或者read foo

Re: 请问一下bash命令行参数
发表于 : 2010-09-05 18:46
由 ChenFengyuan
不从stdin,从参数里?写个if判断下?
Re: 请问一下bash命令行参数
发表于 : 2010-09-05 19:41
由 我来学习的
$ echo aa | sh test.sh -n
aa
$ cat test.sh
#!/bin/sh
while [ -n "$1" ]; do
case $1 in
-n)opt_r="yes";shift 1;;
--)shift;break;;
*)break;;
esac
done
if [ "$opt_r" = "yes" ] ; then read a ;else a="1" ;fi
echo $a
[/code]
LZ新手写的有写长不知可不可以
