Bash Command Substitution Syntax Error Unexpected End Of File
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions syntax error unexpected end of file bash script you might have Meta Discuss the workings and policies of syntax error unexpected end of file php this site About Us Learn more about Stack Overflow the company Business Learn more about hiring syntax error unexpected end of file wordpress 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
Syntax Error Unexpected End Of File Shell Script
a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Shell Script Syntax Error: Unexpected End of File up vote 8 down vote favorite 2 In the following script I get an error: syntax error: unexpected end of file What is this syntax error unexpected end of file python error how can I resove it? It is pointing at the line whee the function is called. #!/bin/sh expected_diskusage="264" expected_dbconn="25" expected_httpdconn="20" expected_cpuusage="95" #expected_fd="100" httpdconn=`ps -ef|grep -i httpd|grep -v grep|wc -l` #httpd connections cpu_usage=`ps aux|awk 'NR > 0 { s +=$3 }; END {print s}'` disk_usage=`df -h|awk {'print $2'}|head -n3|awk 'NF{s=$0}END{print s}'` #db_connections=`mysql -uroot -pexxxxxx -s -N -e "show processlist"|wc -l` db_connections=6 cld_alert() { nwconn=$1 cpu_usage=$2 disk_usage=$3 db_connections=$4 message=$5 `touch /tmp/alert.txt && > /tmp/alert.txt` date=`date` echo -e "$date\n" > /tmp/alert.txt echo -e "$message" >> /tmp/alert.txt path="/proc/$httpd/fd/"; cd $path tfd=`ls -l|wc -l`; sfd=`ls -ltr|grep sock|wc -l`; echo "Total fds: $tfd" >> /tmp/alert.txt echo "Socket fds: $sfd" >> /tmp/alert.txt echo "Other fds: $[$tfd - $sfd]" >> /tmp/alert.txt freememory=`vmstat | awk '{if (NR == 3) print "Free Memory:"\$4}'`; echo "Free memory :$freememory" >> /tmp/alert.txt Bufferedmemory=`vmstat | awk '{if (NR == 3) print "Buffered Memory:"\$5}'`; echo "Buffered memory $Bufferedmemory" >> /tmp/alert.txt CacheMemory=`vmstat | awk '{if (NR == 3) print "Cache Memory:
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 unexpected end of file unix Learn more about Stack Overflow the company Business Learn more about hiring developers
Syntax Error Unexpected End Of File Laravel
or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack
Syntax Error Unexpected End Of File Expecting Function (t_function)
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 bash script, line 30: syntax error: unexpected end http://stackoverflow.com/questions/9886268/shell-script-syntax-error-unexpected-end-of-file of file up vote 1 down vote favorite I`v wrote some script, and have unexpected end of file echo off if [$JAVA_HOME = ""]; then goto no_java_home fi if [$SRV_HOME = ""]; then goto no_srv_home fi echo Uses JAVA_HOME=$JAVA_HOME echo Uses SRV_HOME=$SRV_HOME export ACP="" export ACP=$ACP;$JAVA_HOME/lib/tools.jar export ACP=$ACP;$SRV_HOME/ant/lib/ant.jar export ACP=$ACP;$SRV_HOME/ant/lib/ant-launcher.jar export ACP=$ACP;$SRV_HOME/ant/lib/ant-nodeps.jar export ACP=$ACP;$SRV_HOME/ant/lib/optional.jar export ACP=$ACP;$SRV_HOME/ant/lib/ant-contrib-1.0b3.jar $JAVA_HOME/bin/java -Xmx512m -classpath $ACP org.apache.tools.ant.Main -buildfile $SRV_HOME/ant/ant_script.xml %* goto ends no_srv_home: http://stackoverflow.com/questions/4032089/bash-script-line-30-syntax-error-unexpected-end-of-file clear echo "You should set the TMX_HOME environment variable. For example: TMX_HOME=d:\MYSERVER" goto ends no_java_home: clear echo "You should set the JAVA_HOME environment variable" goto ends ends: echo "OK" Where is my problem? linux bash shell share|improve this question edited Oct 27 '10 at 14:49 Dennis Williamson 167k42235305 asked Oct 27 '10 at 10:14 slavig 1912316 Bash doesn't have goto or echo off and you have to put a space after [ and before ]. You may not need to export the ACP variable since it is being passed as an argument (does Java look for it in its environment?). –Dennis Williamson Oct 27 '10 at 14:54 add a comment| 3 Answers 3 active oldest votes up vote 3 down vote accepted Your problem is that your script looks like a haphazard mix of bash and cmd syntax. Here's a bash script. if [ "$JAVA_HOME" = "" ]; then echo 1>&2 "$0: You need to set the JAVA_HOME variable, e.g.: export JAVA_HOME='c:/java'" exit 2 fi if [ "$SRV_HOME" = "" ]; then echo 1>&2 "$0: You need to set the SRV_HOME variable, e.g.: export SRV_HOME='d:/myserver'" exit 2 fi echo "$0: Uses JAVA_HOME=$JAVA_HOME" echo "$0: Uses SRV_HOME=$SRV_HOME" ACP="$JAVA_HOME/li
here for a quick overview of the site Help Center Detailed answers to any http://unix.stackexchange.com/questions/154427/unexpected-eof-while-looking-for-matching-bash-script questions you might have Meta Discuss the workings and policies of http://linuxcommand.org/wss0100.php 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 syntax error 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 unexpected EOF while looking for matching `"' - bash script up vote syntax error unexpected 7 down vote favorite 1 I just wrote a bash script (im a Newbie to shell-scripting ;) ) and always getting this EOF-Error. So here is my script (only works on OS X): #!/bin/bash #DEFINITIONS BEGIN en_sq() { echo -e "Enabling smart quotes..." defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool true status=$(defaults read NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool) if [ "$status" = "1" ] then echo -e "Success! Smart quotes are now enabled." SUCCESS="TRUE" else echo -e "Sorry, an error occured. Try again." fi } di_sq() { echo -e "Disabling smart quotes..." defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false status=$(defaults read NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool) if [ "$status" = "0" ] then echo -e "Success! Smart quotes are now disabled." SUCCESS="TRUE" else echo -e "Sorry, an error occured. Try again." fi } en_sd() { echo -e "Enabling smart dashes..." defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool true status=$(defaults read NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool) if [ "$status" = "1" ] then echo -e "Success! Smart dashes are now enabled." SUCCESS="TRUE" e
Out Of Trouble by William Shotts, Jr. Now that our scripts are getting a little more complicated, I want to point out some common mistakes that you might run into. To do this, create the following script called trouble.bash. Be sure to enter it exactly as written. #!/bin/bash number=1 if [ $number = "1" ]; then echo "Number equals 1" else echo "Number does not equal 1" fi When you run this script, it should output the line "Number equals 1" because, well, number equals 1. If you don't get the expected output, check your typing; you made a mistake. Empty variables Edit the script to change line 3 from: number=1 to: number= and run the script again. This time you should get the following: [me@linuxbox me]$ ./trouble.bash /trouble.bash: [: =: unary operator expected. Number does not equal 1 As you can see, bash displayed an error message when we ran the script. You probably think that by removing the "1" on line 3 it created a syntax error on line 3, but it didn't. Let's look at the error message again: ./trouble.bash: [: =: unary operator expected We can see that ./trouble.bash is reporting the error and the error has to do with "[". Remember that "[" is an abbreviation for the test shell builtin. From this we can determine that the error is occurring on line 5 not line 3. First, let me say there is nothing wrong with line 3. number= is perfectly good syntax. You will sometimes want to set a variable's value to nothing. You can confirm the validity of this by trying it on the command line: [me@linuxbox me]$ number= [me@linuxbox me]$ See, no error message. So what's wrong with line 5? It worked before. To understand this error, we have to see what the shell sees. Remember that the shell spends a lot of its life substituting text. In line 5, the shell substitutes the value of number where it sees $number. In our first try (when number=1), the shell substituted 1 for $number like so: if [ 1 = "1" ]; then However, when we set number to nothing (number=), the shell saw this after the substitution: if [ = "1" ]; then which is an error. It also explains the rest of the error message we received. The "=" is a binary operator; that is, it expects two items to operate upon - one on each side. What the shell was trying to tell us was that there was only one item and there should have been a unary operator (like "!") that only operates on a single item. To fix this problem, change line 5 to read: if [ "$number" = "1" ]; then Now when the shell performs the substitution it will see: if [ "" = "1" ]; then which correctly expresses our intent. This brings up an important thing to remember when you are writing your scripts. Consider what happ