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
1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

+1. @claybanks, note the necessary use of double quotes everywhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.