Home Man
Search
Today's Posts
Register

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'

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 01-03-2018
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
# 2  
Old 01-03-2018
Try enclosing the for loop in braces or parentheses (not the nohup nor the & ).
# 3  
Old 01-03-2018
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 01-03-2018
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)
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Syntax error near unexpected token Kamesh G UNIX for Beginners Questions & Answers 1 05-01-2018 03:21 AM
Syntax error near unexpected token `else' masubram Shell Programming and Scripting 14 08-02-2016 06:29 AM
Syntax error near unexpected token `|' Meacham12 Shell Programming and Scripting 7 11-26-2013 12:50 PM
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 'else' Ren_kun Homework & Coursework Questions 6 08-18-2011 05:40 AM
syntax error near unexpected token `=' jaango123 Shell Programming and Scripting 3 02-21-2011 07:11 AM
Syntax error near unexpected token engr.jay UNIX for Dummies Questions & Answers 6 09-27-2010 12:35 AM
syntax error near unexpected token '{ MandyR UNIX for Advanced & Expert Users 2 05-14-2010 09:03 AM
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 03:32 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password