Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 通过sh脚本[UNIX]接受多个参数_Bash_Unix_Arguments_Sh - Fatal编程技术网

Bash 通过sh脚本[UNIX]接受多个参数

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

我在这里尝试的是允许用户输入多个参数(文件名),并将它们发送到我创建的回收站 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
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@克莱班克斯,请注意在任何地方都必须使用双引号。