Bash For 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 this site About Us Learn more about Stack Overflow db2 bash syntax error near unexpected token the company Business Learn more about hiring developers or posting ads with us Stack Overflow
Bash Syntax Error Near Unexpected Token Mac
Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of
Bash Syntax Error Near Unexpected Token Newline
4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Confusing syntax error near unexpected token 'done' up vote 4 down vote favorite I am trying to learn
Bash Syntax Error Near Unexpected Token Mysql
shell scripting, so I created a simple script with a loop that does nothing: #!/bin/bash names=(test test2 test3 test4) for name in ${names[@]} do #do something done however, when I run this script I get the following errors: ./test.sh: line 6: syntax error near unexpected token done' ./test.sh: line 6: done' What have I missed here? are shell scripts 'tab sensitive'? bash shell syntax for-loop syntax-error share|improve this question asked May 10 '12 wget bash syntax error near unexpected token at 12:38 fenerlitk 71651633 add a comment| 5 Answers 5 active oldest votes up vote 3 down vote accepted No, shell scripts are not tab sensitive (unless you do something really crazy, which you are not doing in this example). You can't have an empty while do done block, (comments don't count) Try substituting echo $name instead #!/bin/bash names=(test test2 test3 test4) for name in ${names[@]} do printf "%s " $name done printf "\n" output test test2 test3 test4 share|improve this answer edited May 10 '12 at 13:25 answered May 10 '12 at 12:51 shellter 22.4k53962 thanks that works =), is there a way I can get all output in one line? –fenerlitk May 10 '12 at 13:03 1 I'm glad that helped. See my edit. Good luck. –shellter May 10 '12 at 13:04 1 note that echo is very handy to print line-by-line data as the original example showed. Learn about printf (search here on S.O. for examples) as it really powerful and flexible aid in formatting the printing of your data. Good luck. –shellter May 10 '12 at 13:14 5 A valid "no-op" command is : –glenn jackman May 10 '12 at 13:37 1 @glennjackman : yes, good point. As fenerlitk said 'I am trying to learn
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 company Business Learn more about hiring developers or posting bash syntax error near unexpected token done' ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the bash syntax error near unexpected token echo' 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: bash syntax error near unexpected token (' ubuntu Sign up bash for loop work in command line, but failed in script up vote 3 down vote favorite 1 When a run a for statement in debian bash command line, it works fine. But when I run it in a http://stackoverflow.com/questions/10534186/confusing-syntax-error-near-unexpected-token-done sh script or run it with bash command, it's keeping report "error near unexpected token `do'" Where is the difference? [leon@www] ~/tmp $ for i in {1..10}; do echo $i; done 1 2 3 4 5 6 7 8 9 10 [leon@www] ~/tmp $ bash for i in {1..10}; do echo $i; done -bash: syntax error near unexpected token `do' BTW, all works fine in centos enviorment. bash for-loop debian share|improve this question asked Aug 15 '11 at 8:43 leon 1,47431425 add http://stackoverflow.com/questions/7063058/bash-for-loop-work-in-command-line-but-failed-in-script a comment| 3 Answers 3 active oldest votes up vote 5 down vote Use the -c option so that bash reads the commands from the string you pass in. Also, use single quotes around the command. bash -c 'for i in {1..10}; do echo $i; done' share|improve this answer answered Aug 15 '11 at 8:55 dogbane 136k42235322 add a comment| up vote 3 down vote your bash command line ends with the first ; so it gets executed separately as: bash for i in {1..10}; do echo $i; done and man bash says command argument should be a file to load: bash [options] [file] share|improve this answer answered Aug 15 '11 at 8:52 atlau 324210 add a comment| up vote 0 down vote You can wrap all your script inside inverted commas or in a file. Because here, you're doing bash for i in {1..10} then do echo $i and so on. You should use -c option if you don't put it in a file. share|improve this answer edited Aug 15 '11 at 8:57 answered Aug 15 '11 at 8:49 Cydonia7 2,5761126 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 and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse ot
communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start 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 http://askubuntu.com/questions/372926/bash-syntax-error-near-unexpected-token this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Ask Ubuntu Questions Tags Users Badges Unanswered Ask Question _ http://unix.stackexchange.com/questions/151911/syntax-error-near-unexpected-token Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody syntax error can answer The best answers are voted up and rise to the top bash: syntax error near unexpected token `(' up vote 4 down vote favorite 2 I am trying to download flareget download manager via wget I get error wget http://www.flareget.com/files/flareget/debs/amd64/flareget_2.3-24_amd64(stable)_deb.tar.gz bash: syntax error near unexpected token `(' Why is that error coming and what is the solution for that? bash scripts wget share|improve syntax error near this question asked Nov 8 '13 at 10:27 Registered User 1,15472237 add a comment| 2 Answers 2 active oldest votes up vote 6 down vote accepted You should use single quotes ' or double quotes " around the URL in this case (and in general): wget 'http://www.flareget.com/files/flareget/debs/amd64/flareget_2.3-24_amd64(stable)_deb.tar.gz' From now, you should use this method in general when you use a string which contain parentheses as argument in a command. That is because parentheses are used for grouping by the shell such that they are not communicated in any way to a command. So, the bash shell will give you a syntax error: $ echo some (parentheses) bash: syntax error near unexpected token `(' $ echo 'some (parentheses)' some (parentheses) share|improve this answer edited Nov 8 '13 at 11:40 answered Nov 8 '13 at 10:30 Radu Rădeanu 77.6k24168256 add a comment| up vote 2 down vote It's because of the brackets. You need to escape them like this: wget http://www.flareget.com/files/flareget/debs/amd64/flareget_2.3-24_amd64\(stable\)_deb.tar.gz Now it should work. share|improve this answer answered Nov 8 '13 at 10:29 chaos 13.3k74158 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using
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 company Business Learn more about hiring developers or posting ads 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 best answers are voted up and rise to the top Syntax error near unexpected token `(' up vote 10 down vote favorite 2 When I use below code in SSH terminal for CentOS it works fine: paste <(printf "%s\n" "TOP") But if I place the same line code in a shell script (test.sh) and run shell script from terminal, it throws error as this ./test.sh: line 30: syntax error near unexpected token (' ./test.sh: line 30: paste <(printf "%s\n" "TOP") How can I fix this problem? shell share|improve this question edited Aug 24 '14 at 14:30 Braiam 16.8k95599 asked Aug 24 '14 at 14:24 NecNecco 1761110 How exactly are you running it? what '#!' line (if any) starts your script? It looks like you are invoking a shell interpreter that doesn't support that syntax (e.g. dash instead of bash). –steeldriver Aug 24 '14 at 14:28 I have #!/bin/sh at the top. I executed as bash test.sh but it did not work either. –NecNecco Aug 24 '14 at 14:49 bash in POSIX mode doesn't support that syntax either (when called with --posix or as /bin/sh). Use #!/bin/bash. –jordanm Aug 24 '14 at 15:21 @NecNecco: Do you have POSIXLY_CORRECT variable set when you start bash? –cuonglm Aug 24 '14 at 15:31 @jordanm switching to #!/bin/bash at the top fixed the problem. –NecNecco Aug 24 '14 at 16:51 | show 4 more comments 2 Answers 2 active oldest votes up vote 15 down vote accepted Process substitution is not specified by POSIX, so not all POSIX shell support it, only some shells like bash, zsh, ksh88, ksh93 support. In Centos system, /bin/sh is symlink to /bin/bash. When bash is invoked with name sh, bash enters posix mode (Bash Startup Files - Invoked with name sh). In posix mode, process substitution is not supported, cause syntax error. Script should work, if you call bash directly bash test.sh. If not, maybe bash has entered posix mode. This can be occur if you start bash with --posix argument or variable POSIXLY_CORRECT is set when bash st