Results 1 to 2 of 2
./test.sh: line 3: syntax error near unexpected token `cd'
./test.sh: line 3: `cd $f'
--------------------------------
#!/bin/bash
for f in "dir1 dir2";
cd $f
do
print "print test1"
echo "echo test1"
...
- 11-10-2010 #1Just Joined!
- Join Date
- Nov 2010
- Posts
- 2
cd error from for loop
./test.sh: line 3: syntax error near unexpected token `cd'
./test.sh: line 3: `cd $f'
--------------------------------
#!/bin/bash
for f in "dir1 dir2";
cd $f
do
print "print test1"
echo "echo test1"
cd ..
done
- 11-10-2010 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,970
Placing quotes around dir1 dir2 result in "cd $f" evaluating to "cd dir1 dir2", which is an error. Try "for f in dir1 dir2 ; do ... ; done". Also, remember the spaces as shown before and after commands that are on the same line, including the commands "do" and "done". So, try this:
BTW, the "print" command is probably an error, depending upon your system, and will probably generate a "print: command not found" error.Code:#!/bin/bash for f in dir1 dir2 do cd $f print "print test1" echo "echo test1" echo dir=`pwd` cd .. done
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote