I'm writing an alias that takes input for a file name and then after making sure the file is regular and readable copies the file using
cp -i to the back up folder
I am very new to UNIX so I am experiencing some difficulties accomplishing this. Here is my code:
alias getname='read filename' alias vfile='getname; if [ ! -f $filename ]; then echo "Irregular file"; (exit 1); elif [ ! -r $file ]; then echo "Not readable"; (exit 2); fi;' alias backup='vfile; if [ vfile ]; then cp -i $filename $home/Backup; fi;'
I have tested the
vfile alias and it works, the errors I am getting are:
-bash: syntax error near unexpected token ';'
I started getting this error as soon as I included
vfile as the first operation; if I don't run
vfile before the if statement, it will use the filename from the last time it ran. I have to make sure that
vfile did not produce an error before I can copy it.
Before I added
vfile as the first command I got this error:
cp: cannot create regular file '/Backup/*': No such file or directory
but there is indeed a directory named Backup in my home folder so I don't know what's causing this either.