检查传递给 Bash 脚本的参数数量 - Check number of arguments passed to a Bash script

问题:

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章