问题:
I would like my Bash script to print an error message if the required argument count is not met.如果未满足所需的参数计数,我希望我的 Bash 脚本打印错误消息。
I tried the following code:我尝试了以下代码:
#!/bin/bash
echo Script name: $0
echo $# arguments
if [$# -ne 1];
then echo "illegal number of parameters"
fi
For some unknown reason I've got the following error:由于某些未知原因,我收到以下错误:
test: line 4: [2: command not found
What am I doing wrong?我究竟做错了什么?
解决方案:
参考一: https://en.stackoom.com/question/1FuZG参考二: https://stackoom.com/question/1FuZG