Aslet
Aslet

Reputation: 21

Bash script with mv won't work

I've written the following bash script:

alias uploadToCloud='
say "Which file would you like me to upload, $name?"
echo "File?"
read $file
mv $file ~/Dropbox
say "It will be online soon."
echo "The file will be online soon."
'

But when running it I get the following output:

usage: mv [-f | -i | -n] [-v] source target
       mv [-f | -i | -n] [-v] source ... directory

I am really not sure of what I am doing wrong.

Upvotes: 1

Views: 367

Answers (1)

jaypal singh
jaypal singh

Reputation: 77105

Make a function instead of alias in your profile file. Something like this -

uploadToCloud() {
    echo "which file"
    read file
    mv "$file" ~/Dropbox
}

A function should be used when you need to do something more complex. Your requirement is a perfect example of a function because it is too complex for an alias.

An alias should be used for tasks that effectively change the default options of a command.

Upvotes: 4

Related Questions