Bash 通过sh脚本[UNIX]接受多个参数
我在这里尝试的是允许用户输入多个参数(文件名),并将它们发送到我创建的回收站 sh脚本称为“sh safe_rm” 所以我会这样做: $]sh安全\u rm测试文件2测试文件3 我需要两个文件都能通过,有什么想法吗Bash 通过sh脚本[UNIX]接受多个参数,bash,unix,arguments,sh,Bash,Unix,Arguments,Sh,我在这里尝试的是允许用户输入多个参数(文件名),并将它们发送到我创建的回收站 sh脚本称为“sh safe_rm” 所以我会这样做: $]sh安全\u rm测试文件2测试文件3 我需要两个文件都能通过,有什么想法吗 file=$1 if [ $# -eq 0 ] then echo "You have not entered a file" exit elif [ -d $file ] then echo "Your file is a directory" exit
file=$1
if [ $# -eq 0 ]
then
echo "You have not entered a file"
exit
elif [ -d $file ]
then
echo "Your file is a directory"
exit
elif [ -e $file ]
then
sendToBin
else
echo "Your file $file does not exist"
exit
fi
试着这样做:
sh safe_rm testFile2 testFile 3
for var in "$@"
do
echo "$var"
done
这将打印:
testFile2
testFile
3
您将需要对此进行调查:+1@克莱班克斯,请注意在任何地方都必须使用双引号。