![](/img/trans.png)
[英]Assignment asking to use grep command, how would I write a command when it is fine with the find command?
[英]How would I write an 'if' command that checks to see if there are multiple arguments?
我需要創建一個腳本,該腳本使用一個“if”命令來檢查是否只有一個參數。 如果有多個參數,我需要它來回顯“用法:只給出 1 個參數,要查找的字符串”,然后立即退出。
歡迎來到 Stackoverflow。
這應該可以解決問題:
if [ "$#" -gt 1 ]; then
echo "Usage: give exactly 1 argument, the string to be looked for"
exit 0
else
echo the expected processing happens in this section of this code
fi
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.