Bash script problem: syntax error near unexpected token `do
Hello,
I am having a problem running a bash script, and I get the following problem: Code:
: command not found Code:
#!/usr/bin/bash I have a bunch of test cases that I ran in various folders. Each folder has a .txt file with some data I would like to collect and write into one .txt file. The read and write part is executed by the 'heatFluxGather' code. The bash just retrieves the data. Any recommendations as to how to fix or improve the script would be nice too. Thanks, Robert |
I changed your script like this (/usr/bin/bash to /bin/bash and preceded your cp, heatFluxGather and rm with echo),
Code:
[root@athlon ~]# cat heatFlux Code:
[root@athlon ~]# ./heatFlux | head I suspect you are having a problem with lineend characters. The 'file' command should tell you what they are (if that command is available on the Unix you are on). Code:
[root@athlon ~]# file heatFlux Code:
[root@athlon ~]# unix2dos heatFlux Code:
[root@athlon ~]# dos2unix heatFlux Code:
[root@athlon ~]# hexdump -C -n 64 heatFlux Code:
[root@athlon ~]# od -c heatFlux | head If that's the case you can try dos2unix or mac2unix to fix the script file, although they not be available on your flavor of Unix. If bad lineend's are not the case then I can't help. In terms of a suggested style, make your variables upper case ("for a in 10 20..." would be "for A in 10 20..."; and "cp ./a$a/b$b/..." and "...heatFluxGather $a $b" would be "cp ./a$A/b$B/..." and "...heatFluxGather $A $B". I'd lose most of the extra blank lines you have inserted (probably for readability). And I think you want an explicit path to the file in your remove command. (If you have a script with references to a particularly long path or one that is used multiple times, it's common to make it a variable that gets used in multiple places - just don't call it PATH.) ps. you should mention what Unix you are running. My response is for Linux, but in general I think some of it should apply. Hope this helps. |
Thanks, tommylovell. This has been bothering me for a while now. Based on your recommendation, I just opened a new file and rewrote the script with some of your advice, and it worked great. Thanks a lot.
Cheers. |
Thanks, tommylovell. In my case, I was trying to execute the script file(written on Windows system) on linux system. So tried with command as :
Code:
$ dos2unix abc.sh |
All times are GMT -5. The time now is 11:36 PM. |