How To Fix 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
Syntax Error Near Unexpected Token Elif' Shell Script
Learn more about Stack Overflow the company Business Learn more about hiring developers syntax error near unexpected token elif' bash or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack syntax error elif unexpected 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 How can I fix shell error “syntax
Syntax Error Near Unexpected Token (' In Linux
error near unexpected token 'elif'” up vote 2 down vote favorite I have this run as a Shell Script target in my Xcode project # shell script goes here genstrings -u -a -o en.lproj *[hmc] */*[hmc] */*/*[hmc] if [ -f "$PROJECT_DIR/build/Release-macosx/UnicodeEscape" ] then build/Release-macosx/UnicodeEscape "en.lproj/Localizable.strings" elif [ -f "$PROJECT_DIR/build/Debug-macosx/UnicodeEscape" ] then build/Debug-macosx/UnicodeEscape "en.lproj/Localizable.strings" fi exit 0 I get this error: /Users/aa/Dropbox/Developer/Pandamonia LLC/iPhone/Acey Deucey/build/Acey Deucey.build/Release/GenerateLocalizedStrings.build/Script-00F66869125625D9009F14DA.sh: line 7: syntax
Syntax Error Near Unexpected Token (' Bash
error near unexpected token elif' /Users/aa/Dropbox/Developer/Pandamonia LLC/iPhone/Acey Deucey/build/Acey Deucey.build/Release/GenerateLocalizedStrings.build/Script-00F66869125625D9009F14DA.sh: line 7:elif [ -f "$PROJECT_DIR/build/Debug-macosx/UnicodeEscape" ] then' Command /bin/sh failed with exit code 2 shell share|improve this question edited May 8 '12 at 13:37 Jens 36.4k863105 asked Oct 1 '10 at 15:00 Alexsander Akers 12.6k74674 add a comment| 4 Answers 4 active oldest votes up vote 5 down vote accepted First of all, do not tag it bash and sh, you have one shell, type echo $SHELL to know which shell you use, or put a shebang at the start of your script (#!/usr/bin/env bash) put semicolons after your commands, including [ ... ] which is an alias for test. Command terminators are newline, ;, &&, || and & and are mandatory. You can put several commands between if and then, so those semicolons are mandatory. if [ -f "$PROJECT_DIR/build/Release-macosx/UnicodeEscape" ] ; then build/Release-macosx/UnicodeEscape "en.lproj/Localizable.strings" ; elif [ -f "$PROJECT_DIR/build/Debug-macosx/UnicodeEscape" ] ; then build/Debug-macosx/UnicodeEscape "en.lproj/Localizable.strings" ; fi share|improve this answer edited Oct 1 '10 at 15:08 answered Oct 1 '10 at 15:02 Benoit 47.1k12128190 The ; at the end of the statements are useless null-statements. –Jens May 8 '12 at 10:18 @Jens: except if you don
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 syntax error near unexpected token `&' about Stack Overflow the company Business Learn more about hiring developers or posting
Syntax Error Near Unexpected Token `elif' In Unix
ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack syntax error near unexpected token `(' c 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 “elif” in bash up vote 0 http://stackoverflow.com/questions/3840375/how-can-i-fix-shell-error-syntax-error-near-unexpected-token-elif down vote favorite Here's my code to display some dialogs. #!/bin/bash output=$(zenity --list --text="Choose action" --column= --hide-header "Hidden Files" "Desktop") if [ $output = "Hidden Files"] then output2=$(zenity --list --text="Do what?" --column= --hide-header "Show" "Hide") if [ $output2 = "Show"] then echo showing files else echo hiding files elif [ $output = "Desktop"];then output3=$(zenity --list --text="Do what?" --column= --hide-header "Show" "Hide") if [ $output2 = "Show"] then echo showing http://stackoverflow.com/questions/8342537/syntax-error-near-unexpected-token-elif-in-bash files else echo hiding files else exit fi I get this error after the first dialog: systool.sh: line 12: syntax error near unexpected token `elif' systool.sh: line 12: `elif [ $output = "Desktop"];then' Whats wrong? bash unix if-statement share|improve this question asked Dec 1 '11 at 14:01 t3hcakeman 58631223 add a comment| 3 Answers 3 active oldest votes up vote 4 down vote accepted You need to close both of your inner if-else statements with a fi. For example: if [ $output2 = "Show"] then echo showing files else echo hiding files fi You also need a space before the closing ] in your if conditions. For example: if [ $output2 = "Show" ] share|improve this answer answered Dec 1 '11 at 14:03 dogbane 137k42236324 2 LOL wow i'm stupid. –t3hcakeman Dec 1 '11 at 14:07 got a new problem... systool.sh: line 14: [: =: unary operator expected –t3hcakeman Dec 1 '11 at 15:19 The if-statement under "Desktop" is referring to the wrong variable. It should be output3, not output2. Change to: if [ $output3 = "Show" ] –dogbane Dec 1 '11 at 15:22 Also, you should always double-quote your variable expansions (unless there's a specific
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 http://unix.stackexchange.com/questions/151911/syntax-error-near-unexpected-token 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 http://superuser.com/questions/1099933/syntax-error-near-unexpected-token-writing-bash-function 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 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? syntax error near shell share|improve this question edited Aug 24 '14 at 14:30 Braiam 16.9k955100 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
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 Super User Questions Tags Users Badges Unanswered Ask Question _ Super User is a question and answer site for computer enthusiasts and power users. 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 `(' writing bash function up vote 0 down vote favorite I have testapi() { docker-compose -f /home/me/projects/api/docker-compose.yml run -e "API_BRANCH=${1-master}" --rm api_test ;} It causes error: $ src bash: /home/me/.bash_profile: line 56: syntax error near unexpected token `(' bash: /home/me/.bash_profile: line 56: `testapi() { docker-compose -f /home/me/projects/api/docker-compose.yml run -e "API_BRANCH=${1-master}" --rm api_test ;}' Running yields help message: $ testapi Run a one-off command on a service. For example: $ docker-compose run web python manage.py shell Any help appreciated, ty linux ubuntu bash docker share|improve this question asked Jul 12 at 14:47 codyc4321 1477 1 Works for me. What's your bash version? –choroba Jul 12 at 14:49 $ bash --version GNU bash, version 4.3.42(1)-release (x86_64-pc-linux-gnu) –codyc4321 Jul 12 at 14:51 1 Does it work with a space before the parentheses? –choroba Jul 12 at 14:57 no bash: /home/me/.bash_profile: line 56: syntax error near unexpected token (' bash: /home/me/.bash_profile: line 56: testwebapi () { docker-compose -f /home/me/work_projects/webapi/docker-compose.yml run -e "WEBAPI_BRANCH=${1-master}" --rm webapi_test ;}' –codyc4321 Jul 12 at 15:30 Do you have an alias defined of the same name as the function? –choroba Jul 12 at 16:31 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote You have defined an alias of the same name as the function. The alias gets expanded (as the profile is sourced in an interactive shell where aliases work) which makes the function definition invalid. share|improve this answer answered Jul 12 at 16:31 choroba 8,85911727 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