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 2 Weeks Ago   -   Original Discussion by gillesi
gillesi's Unix or Linux Image
gillesi gillesi is offline
Registered User
 
Join Date: Feb 2017
Last Activity: 17 January 2018, 8:18 AM EST
Posts: 30
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; 2 Weeks Ago at 06:09 AM.. Reason: Code tags for icode tags
Sponsored Links
    #2  
Old Unix and Linux 2 Weeks Ago   -   Original Discussion by gillesi
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 17 January 2018, 2:48 PM EST
Location: Aachen, Germany
Posts: 11,940
Thanks: 352
Thanked 3,678 Times in 3,376 Posts
Try enclosing the for loop in braces or parentheses (not the nohup nor the & ).
Sponsored Links
    #3  
Old Unix and Linux 2 Weeks Ago   -   Original Discussion by gillesi
apmcd47's Unix or Linux Image
apmcd47 apmcd47 is offline
Registered User
 
Join Date: Feb 2011
Last Activity: 17 January 2018, 11:48 AM EST
Posts: 293
Thanks: 13
Thanked 79 Times in 76 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 2 Weeks Ago   -   Original Discussion by gillesi
MadeInGermany's Unix or Linux Image
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 17 January 2018, 2:10 PM EST
Location: Simplicity
Posts: 3,929
Thanks: 333
Thanked 1,314 Times in 1,184 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 (1 Week Ago)
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 03:37 PM
Syntax error near unexpected token `else' Aryan12345 Shell Programming and Scripting 6 05-23-2013 01:09 PM
Syntax error near unexpected token `(' iiiiiiiiiii Shell Programming and Scripting 2 05-02-2012 11:26 AM
Syntax error near unexpected token `done' Lenora2009 Shell Programming and Scripting 21 04-27-2010 10:00 PM
Syntax error near unexpected token tomailraj UNIX for Advanced & Expert Users 2 08-23-2009 10:07 AM



All times are GMT -4. The time now is 04:20 PM.