Bash Elif Syntax Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings python elif syntax error and policies of this site About Us Learn more about Stack Overflow syntax error near unexpected token elif the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation bash syntax error near unexpected token done' Tags Users Badges Ask Question 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
Bash Syntax Error Near Unexpected Token Else'
only takes a minute: Sign up How can I fix shell error “syntax error near unexpected token 'elif'” up vote 1 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 bash syntax error near unexpected token fi' "$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 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.2k863104 asked Oct 1 '10 at 15:00 Alexsander Akers 12.6k74674 add a comment| 4 Answers 4 active oldest votes up vote 4 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 edi
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 bash syntax error invalid arithmetic operator site About Us Learn more about Stack Overflow the company Business Learn more
Bash Syntax Error Near Unexpected Token Then'
about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss
Bash Syntax Error Near Unexpected Token Do'
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 http://stackoverflow.com/questions/3840375/how-can-i-fix-shell-error-syntax-error-near-unexpected-token-elif unexpected token 'elif' up vote 2 down vote favorite #!/bin/bash if [ "$1" = "boot" ] then if [ -f /var/log/boot.log ] then echo /var/log/boot.log elif [ -f /var/log/boot ] then echo /var/log/boot fi fi This shows the output: : command not foundline 8: GetLogfileName.sh: line 15: syntax error near unexpected token `elif' 'etLogfileName.sh: line 15: ` elif [ -f /var/log/boot ] What is http://stackoverflow.com/questions/18741776/syntax-error-near-unexpected-token-elif going wrong here? bash share|improve this question edited Sep 11 '13 at 13:45 Jens 36.2k863104 asked Sep 11 '13 at 12:54 Meena 112 The script as you show it works fine in bash on my system. I think @glennjackman may be on to something with the carriage returns. –lurker Sep 11 '13 at 13:09 Inspect file as hex dump and check if newlines are just 0A, or Dos-style 0D 0A. My favorite command for this: most -b script.sh –hyde Sep 11 '13 at 13:12 add a comment| 2 Answers 2 active oldest votes up vote 6 down vote The garbled error message indicates your file has carriage returns before the newline. Did you edit your script on Windows? Either use your text editor to save the file without carriage returns or run the script through dos2unix (or perhaps d2u) share|improve this answer answered Sep 11 '13 at 13:08 glenn jackman 121k1682161 +1: That's my suspicion too. The OP has been edited a few times, so it may be hard to tell if there's another issue involved. –David W. Sep 11 '13 at 16:13 add a com
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta http://unix.stackexchange.com/questions/304706/bash-syntax-error-near-unexpected-token-elif 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 syntax error 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 bash: syntax error near unexpected token `elif' [duplicate] up vote 2 down vote favorite This question already has an answer here: command not found and syntax syntax error near error near unexpected token 3 answers The shell script snippet is given below if [[ $OS == Linux ]] ; then LINUX_FC=gfortran # # set 32 or 64 Bits executable # ARCH=`uname -m` echo "PROCESSOR IS: $ARCH" if [ [ $ARCH == x86_64 ] ] ; then BITS=SIXTYFOUR; else BITS=THIRTYTWO; fi elif [[ $OS == Darwin ]] ; then DARWIN_FC=gfortran; else BITS=THIRTYTWO; fi; Error is OPERATING SYSTEM IS: Linux : command not found jobcomp1: line 34: syntax error near unexpected token `elif' 'obcomp1: line 34: `elif [ [ $OS == Darwin ] ] ; then bash shell-script shell windows share|improve this question edited Aug 20 at 23:09 Gilles 369k666681119 asked Aug 20 at 18:57 jay 111 marked as duplicate by Gillesbash Users with the bash badge can single-handedly close bash questions as duplicates and reopen them as needed. Aug 20 at 23:10 This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. ShellCheck is your friend. –Kusalananda Aug