Linux 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 and policies of this site About Us Learn syntax error unexpected in shell script more about Stack Overflow the company Business Learn more about hiring developers or posting syntax error ( unexpected bash array ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question syntax error at line 1 (' unexpected in shell script 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 ( Unexpected Ubuntu
best answers are voted up and rise to the top `Syntax error: “(” unexpected` when creating an array up vote 1 down vote favorite 1 I have two (Debian) Linux servers. I am creating a shell script. On the first one I create an array thus: #!/bin/bash target_array=( "/home/user/direct/filename -p123 -r" ) That works fine. But when I run this on the other server I get: Syntax error: "(" unexpected ksh syntax error unexpected As far as I can tell both servers are the same. Can anyone shed some light on why this doesn't work? If I type it into the terminal directly it is fine?? It would appear that when I run it as sh scriptname.sh I get the error, but if I run it as ./scriptname.sh it seems to be ok. What's the difference? bash shell-script array share|improve this question edited Jan 7 at 23:36 Gilles 372k696761127 asked Jan 7 at 14:42 IGGt 398214 Did you copy-pasted the script between the two server? try cat -v script to see if there are spurious char. –LilloX Jan 7 at 14:50 2 sh is not bash and so running it as sh scriptname.sh is wrong –Eric Renouf Jan 7 at 15:01 add a comment| 3 Answers 3 active oldest votes up vote 7 down vote accepted When you use ./scriptname.sh it executes with /bin/bash as in the first line with #!. But when you use sh scriptname.sh it executes sh, not bash. The sh shell has no syntax to create arrays, but Bash has the syntax you used. share|improve this answer edited Jan 7 at 23:37 Gilles 372k696761127 answered Jan 7 at 15:06 Konstantin Morenko 2086 OK, that ma
Syntax error: "(" unexpected stigalaJuly 12th, 2007, 09:33 AMHi, I'm trying to run a script on ubuntu 7.04; stig@stig-laptop:~/mosesdecoder$ ./regenerate-makefiles.sh ./regenerate-makefiles.sh: 13: Syntax error: "(" unexpected but then I get the line 1: syntax error: unexpected word (expecting ")") syntax error. Below is the first lines in the script, line 13 in
Syntax Error Near Unexpected Token In Shell Script
red. #!/bin/sh # NOTE: # Versions 1.9 (or higher) of aclocal and automake are required. # For Mac OSX
Syntax Error At Line 1 (' Unexpected Solaris
users: # Standard distribution usually includes versions 1.6. # Get versions 1.9 or higher # Set the following variable to the correct paths #ACLOCAL="/path/to/aclocal-1.9" #AUTOMAKE="/path/to/automake-1.9" function die () { echo "$@" >&2 exit http://unix.stackexchange.com/questions/253892/syntax-error-unexpected-when-creating-an-array 1 } ... I already have automake (GNU automake 1.9.6) and aclocal (GNU automake 1.9.6). Setting the paths is only for Mac OSX users, so I didn't try to set any of those paths. Anyone can explain this? Thanks for any help, Stig Rui PaisJuly 12th, 2007, 10:01 AMHi. the (inexistent) problem is the 1st line in combination with Ubuntu. When you run it using ./ https://ubuntuforums.org/archive/index.php/t-499045.html it will use the shell you mention on first line, in your case: #!/bin/sh if you do a ls -l /bin/sh you will see that it's just a link to dash. Ubuntu, since Edgy, replaced old sh with dash, creating a series of incompatibilities in a lot of scripts... So, either you run: bash regenerate-makefiles.sh or replace first line with: #!/bin/bash (or even remove the 1st line and environment will call it with bash) or (losing generality) adapt it for dash: remove the keyword function: die() { ... } hth stigalaJuly 12th, 2007, 10:55 AMThanks a lot, Rui! I used bash regenerate-makefiles.sh and the script ran perfectly. I guess I'll have to read up on dash, bash and sh to understand the difference between the different shells. Stig Rui PaisJuly 12th, 2007, 11:16 AMNo prob :) sh and bash has more or less the same syntax, so usually no problem came from there... but dash is much more different. it's suppose to be much lighter and faster then bash, being that the reason why they choose it by Edgy days. A lot of people had problem, specially with custom scripts. I still have to manually
Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here. Search Forums Show Threads http://www.unix.com/shell-programming-and-scripting/188983-syntax-error-line-24-unexpected.html Show Posts Tag Search Advanced Search Unanswered Threads Find All Thanked http://stackoverflow.com/questions/37862365/sh-linux-syntax-error-word-unexpected Posts Go to Page... learn linux and unix commands - unix shell scripting Syntax error at line 24: `(' unexpected Shell Programming and Scripting Tags if () unexpected Thread Tools Search this Thread Display Modes #1 06-05-2012 Nithz Registered User syntax error Join Date: Aug 2011 Last Activity: 8 June 2012, 4:46 PM EDT Posts: 17 Thanks: 6 Thanked 1 Time in 1 Post Syntax error at line 24: `(' unexpected Hi, I am getting an wired error.... the script is running fine when i run it manually... but the same when i try to run in nohup mode, i am getting error in shell script Code: if [ $(grep -c "My Daddy" processfile.txt) -ne 0 ] Error: Code: syntax error at line 24: `(' unexpected The above if is the 24th line!!! I dont understand the error @ all! Remove advertisements Sponsored Links Nithz View Public Profile Find all posts by Nithz #2 06-05-2012 gary_w Registered User Join Date: Oct 2010 Last Activity: 28 September 2016, 2:16 PM EDT Posts: 446 Thanks: 32 Thanked 96 Times in 88 Posts Works fine for me using ksh and bash when run from both command line and nohup'ed. What is your shell? if you are using the bourne shell, the "$( )" command substitution syntax is not supported. Use backquotes instead: Code: if [ `grep -c "My Daddy" processfile.txt` -ne 0 ] And make sure you test for the existence of processfile.txt first too. Make sure your script starts with a "shebang", which tells the login shell what shell to use when runnning the script: Code: #!/bin/ksh ..... Rest of code... The Following User Says Thank You to gary_w For This U
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 Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up SH linux: Syntax error: word unexpected up vote 3 down vote favorite I want know what am I doing wrong in this code: #!/bin/sh SERVICE_NAME=neocloud PATH_TO_JAR=/etc/neocloud/cloud.jar PID_PATH_NAME=/tmp/neocloud-pid case $1 in start) echo "Starting $SERVICE_NAME ..." if [ ! -f $PID_PATH_NAME ]; then nohup java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null & echo $! > $PID_PATH_NAME echo "$SERVICE_NAME started ..." else echo "$SERVICE_NAME is already running ..." fi ;; stop) if [ -f $PID_PATH_NAME ]; then PID=$(cat $PID_PATH_NAME); echo "$SERVICE_NAME stoping ..." kill $PID; echo "$SERVICE_NAME stopped ..." rm $PID_PATH_NAME else echo "$SERVICE_NAME is not running ..." fi ;; restart) if [ -f $PID_PATH_NAME ]; then PID=$(cat $PID_PATH_NAME); echo "$SERVICE_NAME stopping ..."; kill $PID; echo "$SERVICE_NAME stopped ..."; rm $PID_PATH_NAME echo "$SERVICE_NAME starting ..." nohup java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null & echo $! > $PID_PATH_NAME echo "$SERVICE_NAME started ..." else echo "$SERVICE_NAME is not running ..." fi ;; esac executing via sh I get the following error message: Syntax error: word unexpected (expecting "in") But in the case command I've the in word. Anyone know how to fix this bug? Thanks a lot! linux bash ubuntu ubuntu-14.04 sh share|improve this question asked Jun 16 at 14:39 pedro.olimpio 727519 what's the value of $1 ? –Thomas Ayoub Jun 16 at 14:45 $1 is the first commandline argument –pedro.olimpio Jun 16 at 14:46 1 Does this give