如果有0个或2个以上的输入,则会向用户显示一条消息。
我不太了解如何检查,从命令行传递了多少值。我可以获得一个简单的程序吗?
答案 0 :(得分:0)
下面是一个示例代码,如果没有传递参数,将返回“无参数传递”:
#!/bin/bash
if [ $# = 0 ];
then
echo "No argument is passed"
fi
参数由具有多个选项的bash处理,下面供您参考:
$# is the number of parameters passed
$0 returns the name of the shell script running as well as its location in the file system
$* gives a single word containing all the parameters passed to the script
$@ gives an array of words containing all the parameters passed to the script