0

What I'm trying to do here is allow users to enter multiple arguments (filenames) and send them to a recycle bin I have created the sh script is called "sh safe_rm"

so I would do this:

$] sh safe_rm testFile2 testFile 3

I need both files able to be passed, any ideas?

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
Clay Banks
  • 4,483
  • 15
  • 71
  • 143

1 Answers1

2

Try something like this:

sh safe_rm testFile2 testFile 3

for var in "$@"
do
    echo "$var"
done

This will print:

testFile2
testFile
3

See this post for more info

Community
  • 1
  • 1
1337holiday
  • 1,924
  • 1
  • 24
  • 42