問題:
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