Echo Syntax Error Near Unexpected Token
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of syntax error near unexpected token c this site About Us Learn more about Stack Overflow the company Business Learn
Syntax Error Near Unexpected Token Do
more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question
Syntax Error Near Unexpected Token Fi
x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up
Syntax Error Near Unexpected Token Else
syntax error near unexpected token ' - bash up vote 8 down vote favorite 1 I have a written a sample script on my Mac #!/bin/bash test() { echo "Example" } test exit 0 and this works fine by displaying Example When I run this script on a RedHat machine, it says syntax error near unexpected token ' I checked that bash is syntax error near unexpected token javascript available using cat /etc/shells which bash shows /bin/bash Did anyone come across the same issue ? Thanks in advance ! linux bash shell scripting share|improve this question edited Dec 7 '15 at 20:12 Tomasz Jakub Rup 5,01471436 asked Jan 3 '14 at 3:20 user3155779 43113 still the same . . –user3155779 Jan 3 '14 at 3:23 hmm I don't know. I can execute this correctly on a Fedora machine. –Michael Berkowski Jan 3 '14 at 3:25 1 Can you recreate the entire file? Perhaps you have a non-printable in there causing the fault. –Michael Berkowski Jan 3 '14 at 3:28 4 @user3155779 Could you close the question, since the actual problem didn't relate to anything asked here (that is, wasn't found in the code as-given byte-for-byte)? –Charles Duffy Jan 3 '14 at 4:47 3 This question appears to be off-topic because the solution was unrelated to the question as asked. –chepner Jan 3 '14 at 16:23 | show 4 more comments 4 Answers 4 active oldest votes up vote 18 down vote accepted It could be a file encoding issue.
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the syntax error near unexpected token then company Business Learn more about hiring developers or posting ads with us Unix & Linux bash syntax error near unexpected token Questions Tags Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of syntax error near unexpected token perl Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the http://stackoverflow.com/questions/20895946/syntax-error-near-unexpected-token-bash top bash: syntax error near unexpected token `(' up vote 2 down vote favorite I am trying to concatenate some files side by side. I use the pr command in the terminal. It works well, but when I use it in a shell script, I get the following error message: syntax error near unexpected token `(' Here is the script: #!/bin/sh myfile1=toto1.dat myfile1=toto2.dat file_out=mytoto_out.dat touch ${file_out} /usr/bin/pr -mts' ' <( /usr/bin/cut -d' ' -s -f1,2,3,4,5,6,7,8,9,10,11 http://unix.stackexchange.com/questions/143753/bash-syntax-error-near-unexpected-token ${myfile1}) <( /usr/bin/cut -d' ' -s -f8 $myfile2) >>${file_out} echo ${file_out} " is done" shell-script share|improve this question edited Jul 12 '14 at 2:17 polym 4,54312049 asked Jul 10 '14 at 12:20 user77083 11112 Please show us the shell script that fails and not the command that works. –terdon♦ Jul 10 '14 at 12:22 It doesn't throw an error for me. What shell are you using? echo $SHELL –LatinSuD Jul 10 '14 at 12:23 #!/bin/sh myfile1=toto1.dat myfile1=toto2.dat file_out=mytoto_out.dat touch ${file_out} /usr/bin/pr -mts' ' <( /usr/bin/cut -d' ' -s -f1,2,3,4,5,6,7,8,9,10,11 ${myfile1}) <( /usr/bin/cut -d' ' -s -f8 $myfile2) >>${file_out} echo ${file_out} " is done" –user77083 Jul 10 '14 at 12:29 add a comment| 1 Answer 1 active oldest votes up vote 4 down vote On the command line, your shell is bash. In your script you're using /bin/sh. /bin/sh apparently is not bash on your system, and the <() syntax is apparently not present in whatever shell /bin/sh is. Change the shebang (the #!/bin/sh part) to #!/bin/bash. share|improve this answer answered Jul 10 '14 at 12:38 Patrick 34.3k680129 Thanks that is it –user77083 Jul 10 '14 at 12:43 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email a
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more http://unix.stackexchange.com/questions/168482/syntax-error-near-unexpected-token about Stack Overflow the company Business Learn more about hiring developers or posting ads http://wiki.bash-hackers.org/scripting/debuggingtips with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The syntax error best answers are voted up and rise to the top syntax error near unexpected token `<' up vote 3 down vote favorite I am writing a script to read the output of a command to variable a and b. This is the script #!/bin/bash read a b < <(awk '/Application Server/ && !seen[$7]++{printf "%s ", $7}' /tmp/ServerState) echo "The value of a is $a" echo "The value of b is $b" syntax error near and getting the syntax error as : line 3: syntax error near unexpected token `<' line 3: `read a b < <(awk /Application Server/ && !seen[$7]++{echo "%s ", $7} /tmp/ServerState)' But when I am typing the same command in the console it is working for me without any issue. app@user:/tmp> read a b < <(awk '/Application Server/ && !seen[$7]++{printf "%s ", $7}' /tmp/ServerState) app@user:/tmp> echo $a FAILED app@user:/tmp> echo $b STARTED Any help on this is really appreciated. bash shell-script process-substitution share|improve this question edited Nov 18 '14 at 8:32 Gilles 370k686731123 asked Nov 17 '14 at 17:28 Sudev Jash 2513 1 I am not able to reproduce this behavior from script. How are you invoking the script? I am invoking as: $ ./script.sh –Ketan Nov 17 '14 at 17:43 @Ketan I am invoking it as sh script.sh. Just now I tried using ./script.sh and it is giving the desire result. The value of a is FAILED The value of b is STARTED. Thank You so much for the response...Just want to know why it is different while executing the same script using sh file.sh and ./file.sh ?? –Sudev Jash Nov 17 '14 at 18:10 Suppose sh don't allow command substitution. Try invoke by bash script
of Contents Debugging a script Use a unique name for your script Read the error messages Use a good editor Write logfiles Inject debugging code Use shell debug output Simple example of how to interpret xtrace output Making xtrace more useful Debugging commands depending on a set variable Dry-run STDIN driven commands Common error messages Unexpected end of file Unexpected end of file while looking for matching ... Too many arguments !": event not found syntax error near unexpected token `(' The CRLF issue What is the CRLF issue? How did a CR end up in my file? Why do CRs hurt? How can I find and eliminate them? See also Discussion Debugging a script These few lines are not intended as a full-fledged debugging tutorial, but as hints and comments about debugging a Bash script. Use a unique name for your script Do not name your script test, for example! Why? test is the name of a UNIX®-command, and most likely built into your shell (it's a built-in in Bash) - so you won't be able to run a script with the name test in a normal way. Don't laugh! This is a classic mistake Read the error messages Many people come into IRC and ask something like "Why does my script fail? I get an error!". And when you ask them what the error message is, they don't even know. Beautiful. Reading and interpreting error messages is 50% of your job as debugger! Error messages actually mean something. At the very least, they can give you hints as to where to start debugging. READ YOUR ERROR MESSAGES! You may ask yourself why is this mentioned as debugging tip? Well, you would be surprised how many shell users ignore the text of error messages! When I find some time, I'll paste 2 or 3 IRC log-snips here, just to show you that annoying fact. Use a good editor Your choice of editor is a matter of personal preference, but one with Bash syntax highlighting is highly recommended! Syntax highlighting helps you see (you guessed it) syntax errors, such as unclosed quotes and braces, typos, etc. From my personal experience, I can suggest vim or GNU emacs. Write logfiles For more complex scripts, it's useful to write to a log file, or to the system log. Nobody can debug your script without knowing what actually happened and what went wrong. An available syslog interface is logger ( online manpage). Inject debugging code Insert echos everywhere you can, and print to stderr: echo "DEBUG: cu