1
我是新來的shell腳本,我正在寫這個腳本來創建具有權限的文件並檢查文件是否存在。一切工作正常,但是當我沒有指定參數說它缺少參數,但仍然給我沒有這樣的文件或目錄錯誤,我沒有得到。有人可以幫忙嗎?錯誤檢查 - shellscript
代碼:
#!/bin/bash`enter code here`
# checking the argument
if [[ ! $1 ]]; then
echo "missing argument, please check !"
fi
# variable holding the script name.
scriptname="$1"
# creates shellscript and changes the permissions of script to u+x.
# Adds #!/bin/bash line to script.
if [[ ! -e "${scriptname}" ]]; then
echo "#!/bin/bash" >> "${scriptname}" && chmod u+x "${scriptname}"
else
echo "file " ${scriptname} " exists, create a new file."
fi
'回聲後「失蹤的說法,請檢查!」'你可能要添加'exit 1'聲明(下一行) – janos
@janos感謝您的糾正,現在工作正常。 – Arun