Skip to main content
typographical fixes
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264

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 $HOME/Backup

I am very new to UNIX so I am experiencing some difficulties accomplishing this. hereHere 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 iI included vfile as the first operation,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 whatswhat's causing this either but any help will be greatly appreciated.

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 $HOME/Backup

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 whats causing this either but any help will be greatly appreciated.

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 $HOME/Backup

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.

Source Link
mike
  • 313
  • 1
  • 3
  • 10

syntax error near token ';'(homework)

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 $HOME/Backup

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 whats causing this either but any help will be greatly appreciated.