I am trying to output a log file from cp usage. I think this can be achieved. In my code I have this.
cp -i -v ~/files/* ~/backups/oldfiles/;; > ~/logs/logfile.log
The error I get is "syntax error near unexpected token '>'
What am I missing?
I am trying to output a log file from cp usage. I think this can be achieved. In my code I have this.
cp -i -v ~/files/* ~/backups/oldfiles/;; > ~/logs/logfile.log
The error I get is "syntax error near unexpected token '>'
What am I missing?
Hi
check for the double ';' at the end of the second path: probably a typo error?
fra
If I take away the second ; it now gives me
"syntax error near unexpected token ')'
My actual code is,
s) cp -i -v ~/files/* ~/backups/oldfiles/; > ~/logs/logfile.log
^ It is part of a case statement
Please try:
s) cp -i -v ~/files/* ~/backups/oldfiles/ > ~/logs/logfile.log ;;
and let us know if you get the desired result (I didn't understand that the instruction was part of a case statement).
fra
Yes, sorry. I worked this out myself but internet was down so could not reply. All working fine now.
Out of curiosity, is there a quick way of asking the user if they want to overwrite the log file in the script like I do with the -i on cp?
I don't think there is a faster way; perhaps somebody else can suggest such a way.
Anyway, 'cat' already offers the '-i' switch... so, who cares? =)
Have a nice day
fra
Sorry, I do not understand how I would implement cp and cat in the one line? I tried
s) cp -iv ~/files/* ~/backups/oldfiles/ > cat -i ~/logs/logfile.log;;
It gives me a not a directory message for the logs area. Not sure what to do.
Try this:
cp -iv ~/files/* ~/backups/oldfiles/ > ~/logs/logfile.log && cat ~/logs/logfile.log
# Or
cp -iv ~/files/* ~/backups/oldfiles/ > ~/logs/logfile.log ; cat ~/logs/logfile.log