Line 2 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 syntax error: "(" unexpected bash this site About Us Learn more about Stack Overflow the company Business syntax error at line 1 (' unexpected in shell script Learn more about hiring developers or posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question syntax error ( unexpected bash array _ 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 syntax error ( unexpected ubuntu 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)
Ksh Syntax Error Unexpected
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 17k955100 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 o
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
Line 1: Syntax Error: Unexpected Word (expecting ")")
ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & Linux syntax error near unexpected token in shell script 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: syntax error word unexpected (expecting ) ) shell script 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: unexpected end of file — Bash script [closed] up vote 0 down vote favorite 1 http://unix.stackexchange.com/questions/151911/syntax-error-near-unexpected-token I am trying to create an spritz app. Everything was working fine, but since yesterday I keep getting this error: ./spritz: line 176: syntax error: unexpected end of file I have checked the script file and everything seems perfect. I am confused, I have an if statement at last and it looks correct! Here is the last portion: #checks if speed is 150 157 if [[ $2 -eq 150 ]]; 158 then 159 starttime=$SECONDS 160 FS=$'\n' 161 for j in `grep --color=always -iP '\b[^aeiou\s]*[aeiou][^aeiou\s]*\K[aeiou]' http://unix.stackexchange.com/questions/193165/syntax-error-unexpected-end-of-file-bash-script $1`; 162 do 163 #Reads the text file in the centre of the screen 164 echo " ___________________" 165 echo " $j"; 166 echo " ___________________" 167 echo " Speed 150 wpm" 168 sleep 0.9; 169 clear; 170 done 171 endtime=$(($SECONDS - $starttime)) 172 echo "You read $words_read words in $endtime seconds!" 173 exit 8 174 fi bash shell-script share|improve this question edited Mar 29 '15 at 5:19 Anthon 47.6k1462125 asked Mar 29 '15 at 1:31 Scott Pearce 46117 closed as unclear what you're asking by mdpc, jasonwryan, Networker, Michael Homer, Archemar Mar 29 '15 at 8:23 Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question. (0) It might have been more useful to show us a diff from the last version that worked. … … … … … … … … Some observations (that probably don’t relate to your current, specific problem): (1) I don’t know of any circumstance where you need an unescaped ; (semicolon) at the end of a line. You can delete the semicolons at the ends of lines 157, 161, 165, 168, and 169. (Or you can leave them in; I guess it’s a question of style.) … (Cont’d) –Scott Mar 29 '15 at 7:46 (C
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://stackoverflow.com/questions/9886268/shell-script-syntax-error-unexpected-end-of-file this site About Us Learn more about Stack Overflow the company Business Learn http://askubuntu.com/questions/656425/syntax-error-near-unexpected-token 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 syntax error 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 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 in shell script 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:"\$6}'`; echo "Cache memory : $CacheMemory" >> /tmp/alert.txt sshconn=`netstat -an|grep 22|wc -l` #ssh connections httpsconn=`netstat -an|grep 443|wc -l` #https connections wwwconn=`netstat -an|grep 80|wc -l` #www connections echo "Disk usage is $disk_usage" >> /tmp/alert.txt echo "DB connections $db_connections" >> /tmp/alert.txt echo "Network connections $nwconn" >> /tmp/alert.txt echo "CPU Usage: $cpu_usage" >> /tmp/alert.txt topsnapshot=`top -n 1 -b` echo "===========================TOP COMMAND SNAPSHOT===================================================="; echo "$topsnapshot" >> /tmp/alert.txt echo"==================PS
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 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 _ 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 can answer The best answers are voted up and rise to the top Syntax error near unexpected token `(' up vote 7 down vote favorite 1 When I use below code in Ubuntu terminal, it works fine: rm !(*.sh) -rf But if I place the same line code in a shell script (clean.sh) and run the shell script from terminal, it throws an error: clean.sh script: #!/bin/bash rm !(*.sh) -rf The error I get: ./clean.sh: line 2: syntax error near unexpected token `(' ./clean.sh: line 2: `rm !(*.sh) -rf' can you help? command-line bash scripts rm share|improve this question edited Aug 9 '15 at 20:03 guntbert 6,104112957 asked Aug 4 '15 at 10:40 Tal 1422212 unix.stackexchange.com/q/220104/13792 –choroba Aug 4 '15 at 10:44 add a comment| 3 Answers 3 active oldest votes up vote 20 down vote accepted rm !(*.sh) is a extglob syntax which means remove all files except the ones that have the .sh extension. In your interactive bash instance, the shell option extglob is on : $ shopt extglob extglob on Now as your script is running in a subshell, you need to enable extglob by adding this at the start of the script : shopt -s extglob So your script looks like : #!/bin/bash shopt -s extglob rm -rf -- !(*.sh) EDIT : To remove all files except .sh extension ones use GLOBIGN