Shell脚本输入(Shell script input)
#!/bin/sh
if test -n $1
then
echo "Some input entered"
echo $1
else
echo "no input entered"
fi
上面的代码应该说“没有输入输入”,如果我不传递一个参数到shell脚本。 当我不传递任何参数时,echo $ 1显示一个空行。 即使没有任何争论,它也会说“输入一些意见”。
#!/bin/sh if test -n $1 then echo "Some input entered" echo $1 else echo "no input entered" fiThe above code is supposed to say "no input entered" if I dont pass an argument to the shell script. the echo $1 shows a blank line when I dont pass any arguments. its saying "some input entered" even without any arguments.
最满意答案
跳过test ,并将报价放在$1 :
#!/bin/sh if [ -n "$1" ] then echo "Some input entered" echo $1 else echo "no input entered" fiSkip test and put quotes around the $1:
#!/bin/sh if [ -n "$1" ] then echo "Some input entered" echo $1 else echo "no input entered" fi更多推荐
发布评论