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