syntax error near unexpected token `do' Linux RedHat
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
syntax error near unexpected token `do' Linux RedHat
I am trying to change one or two portions of file names using this code. The problem is coming from line 4 and 6. When ran as is I get "syntax error near unexpected token `do'". But, if I open a terminal inside the folder I'm trying to work with (stressed) and lose the 'stressed/' the code works fine. I have tried running the dos2unix as well, but it did nothing. I want this in a shell, so it would be ideal if I could get this working from one file. This is my first time posting here, so thank you all for your help.
Also, if there is a command line to move the files back to where I go them after they have been edited, that would be awesome too.
mkdir stressed
mv *C2.tif stressed
stressed/for i in *.tif; do mv $i $(echo $i | sed 's/nd173_T/s01/g'); done
stressed/for file in s01*; do mv "$file" "${file/_XY1_C2/}"
done
I am trying to change one or two portions of file names using this code. The problem is coming from line 4 and 6. When ran as is I get "syntax error near unexpected token `do'". But, if I open a terminal inside the folder I'm trying to work with (stressed) and lose the 'stressed/' the code works fine. I have tried running the dos2unix as well, but it did nothing. I want this in a shell, so it would be ideal if I could get this working from one file. This is my first time posting here, so thank you all for your help.
Also, if there is a command line to move the files back to where I go them after they have been edited, that would be awesome too.
mkdir stressed
mv *C2.tif stressed
stressed/for i in *.tif; do mv $i $(echo $i | sed 's/nd173_T/s01/g'); done
stressed/for file in s01*; do mv "$file" "${file/_XY1_C2/}"
done
Please post more relevant portions of your script, and use [code][/code] tags to encapsulate your code.
Also suggest if this is a bash script that you enable debug by adding "set -xv" before this section in the script to cause verbose debug output.
Quote:
Originally Posted by hazel
Lines 3 & 4 look odd to me. Shouldn't it be:
for i in stressed/*.tif; do ........;done
for file in stressed/s01; do........;done
Not disagreeing with the assessment, however who knows if those are lines 3 & 4 of their script.
I am trying to change one or two portions of file names using this code. The problem is coming from line 4 and 6. When ran as is I get "syntax error near unexpected token `do'". But, if I open a terminal inside the folder I'm trying to work with (stressed) and lose the 'stressed/' the code works fine. I have tried running the dos2unix as well, but it did nothing. I want this in a shell, so it would be ideal if I could get this working from one file. This is my first time posting here, so thank you all for your help.
Also, if there is a command line to move the files back to where I go them after they have been edited, that would be awesome too.
mkdir stressed
mv *C2.tif stressed
stressed/for i in *.tif; do mv $i $(echo $i | sed 's/nd173_T/s01/g'); done
stressed/for file in s01*; do mv "$file" "${file/_XY1_C2/}"
done
Code:
userx@devuan-do:~$ for i in Downloads/* do ; echo $i ; done
bash: syntax error near unexpected token `echo'
userx@devuan-do:~$ for i in Downloads/* ; do echo $i ; done
Downloads/jwmmaker-master
Downloads/jwmmaker-master.zip
userx@devuan-do:~$
your semi colon is in the wrong place. simple as that.
as far as your code I cannot tell how you're actually getting the files from one place to another, or what you're actually trying to do. I got an idea but ...
Code:
mkdir stressed
mv *C2.tif stressed
stressed/for i in *.tif; do mv $i $(echo $i | sed 's/nd173_T/s01/g'); done
stressed/for file in s01*; do mv "$file" "${file/_XY1_C2/}"
done
1 make new dir
2 move file from old dir to new dir change name on move.
3 done
Code:
mkdir newDir
for i in OldDir/*.tif ; do mv -v $i ~/newDir/NewfileName ; done
working example, if you use cp (copy) you will keep originals and get new one with different name somewhere else.
Code:
$ mkdir NewDir
userx@devuan-do:~$ for i in Downloads/*.zip ; do cp -v $i ~/NewDir/GooBw.zip ; done
‘Downloads/jwmmaker-master.zip’ -> ‘/home/userx/NewDir/GooBw.zip’
$ ls NewDir
GooBw.zip
if more than one file , then they will over copy each other ending up with only one, being last moved. you need to create a way to vary the names on move. Using variables will work. string concatenation .. look it up
As already pointed out, please place your code snippets inside [CODE]...[/CODE] tags for better readability. You may type those yourself or click the "#" button in the edit controls.
From the posted example and description, hazel's comments look to be the most on target. Your syntax using the for construct as posted does not appear to be correct.
Code:
stressed/for i in ...
As for moving them back at a later time, simply another mv with appropriately adjusted source and target would be the simplest way, and you will already know how!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.