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 06: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

This User Gave Thanks to MadeInGermany For This Post:
Neo (01-04-2018)
Login to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads 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 04:21 AM
Syntax error near unexpected token `(' ranabhavish How to Post in the The UNIX and Linux Forums 1 05-09-2017 09:10 AM
Syntax error near unexpected token `else' masubram Shell Programming and Scripting 14 08-02-2016 07:29 AM
Syntax error near unexpected token y33t Shell Programming and Scripting 14 11-29-2014 09:33 AM
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 'else' Ren_kun Homework & Coursework Questions 6 08-18-2011 06:40 AM
syntax error near unexpected token `=' jaango123 Shell Programming and Scripting 3 02-21-2011 08:11 AM
Syntax error near unexpected token engr.jay UNIX for Dummies Questions & Answers 6 09-27-2010 01:35 AM
syntax error near unexpected token '{ MandyR UNIX for Advanced & Expert Users 2 05-14-2010 10:03 AM
Syntax error near unexpected token `done' Lenora2009 Shell Programming and Scripting 21 04-27-2010 10:00 PM
Syntax error near unexpected token `(' raghunsi Shell Programming and Scripting 7 02-03-2010 06:40 AM
Syntax error near unexpected token tomailraj UNIX for Advanced & Expert Users 2 08-23-2009 10:07 AM
sh syntax error unexpected token done NullPointer Shell Programming and Scripting 5 04-30-2009 10:28 AM
All times are GMT -4. The time now is 05:53 PM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.