Unix/Linux Go Back    


UNIX for Beginners Questions & Answers If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

Syntax error near unexpected token 'do'

UNIX for Beginners Questions & Answers


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-03-2018   -   Original Discussion by gillesi
gillesi's Unix or Linux Image
gillesi gillesi is offline
Registered User
 
Join Date: Feb 2017
Last Activity: 21 February 2018, 11:40 AM EST
Posts: 36
Thanks: 9
Thanked 0 Times in 0 Posts
Syntax error near unexpected token 'do'

Hello all,

Please i have this command i used to zip different files in differents directory, but i have an error. Note that when i run the command in one directory it works fine.



Code:
/X5/WORK/BGH/INV/REG/pdf/SEND/BGH12523/1/*.fo
/X5/WORK/BGH/INV/REG/pdf/SEND/BGH24523/1/*.fo
/X5/WORK/BGH/INV/REG/pdf/SEND/BGH1023/1/*.fo


In the above path, i want to zip all files with extension .fo

Here is the commands, it works great.



Code:
for FN in /X5/WORK/BGH/INV/REG/pdf/SEND/BGH12523/1/*.fo; do gzip $FN;

But when trying to do it for all directories like below, i have an error



Code:
>nohup for FN in /X5/WORK/BGH/INV/REG/pdf/SEND/BGH*/1/*.fo; do gzip $FN; done &
bash: syntax error near unexpected token `do'

can somebody help?

Last edited by Scott; 01-03-2018 at 05:09 AM.. Reason: Code tags for icode tags
Sponsored Links
    #2  
Old Unix and Linux 01-03-2018   -   Original Discussion by gillesi
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 21 June 2018, 2:51 AM EDT
Location: Aachen, Germany
Posts: 12,913
Thanks: 429
Thanked 3,966 Times in 3,647 Posts
Try enclosing the for loop in braces or parentheses (not the nohup nor the & ).
Sponsored Links
    #3  
Old Unix and Linux 01-03-2018   -   Original Discussion by gillesi
apmcd47's Unix or Linux Image
apmcd47 apmcd47 is online now
Registered User
 
Join Date: Feb 2011
Last Activity: 21 June 2018, 7:38 AM EDT
Posts: 352
Thanks: 16
Thanked 99 Times in 93 Posts


Code:
nohup bash -c 'for FN in /X5/WORK/BGH/INV/REG/pdf/SEND/BGH*/1/*.fo; do gzip $FN; done' &

Note the single quotes before the for and after the done.

Because you used nohup bash didn't recognise the for loop and tried to interpret the do gzip $FN as a separate command.

Andrew
    #4  
Old Unix and Linux 01-03-2018   -   Original Discussion by gillesi
MadeInGermany's Unix or Linux Image
MadeInGermany MadeInGermany is online now Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 21 June 2018, 7:35 AM EDT
Location: Simplicity
Posts: 4,123
Thanks: 358
Thanked 1,401 Times in 1,258 Posts
And command arguments should be quoted.
And a test for file is appropriate.


Code:
for FN in /X5/WORK/BGH/INV/REG/pdf/SEND/BGH*/1/*.fo; do test -f "$FN" && gzip "$FN"; done

The Following User Says Thank You to MadeInGermany For This Useful Post:
Neo (01-04-2018)
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Syntax error near unexpected token '(' sgradywhite Shell Programming and Scripting 7 09-15-2013 02:37 PM
Syntax error near unexpected token `else' Aryan12345 Shell Programming and Scripting 6 05-23-2013 12:09 PM
Syntax error near unexpected token `(' iiiiiiiiiii Shell Programming and Scripting 2 05-02-2012 10:26 AM
Syntax error near unexpected token `done' Lenora2009 Shell Programming and Scripting 21 04-27-2010 09:00 PM
Syntax error near unexpected token tomailraj UNIX for Advanced & Expert Users 2 08-23-2009 09:07 AM



All times are GMT -4. The time now is 07:56 AM.