Shell脚本输入(Shell script input)

编程入门 行业动态 更新时间:2024-10-25 02:28:53
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" fi

The 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" fi

Skip 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

更多推荐

本文发布于:2023-08-04 06:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1412463.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   Shell   input   script

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!