Bash Standard_in 1 Syntax Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions bash syntax error near unexpected token done' you might have Meta Discuss the workings and policies of this bash syntax error near unexpected token else' site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers
Bash Syntax Error Near Unexpected Token Fi'
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
Bash Syntax Error Invalid Arithmetic Operator
community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up (standard_in) 1: syntax error in bash script up vote 0 down vote favorite I'm trying to generate some quasi random numbers to feed into a monte carlo simulation. I'm using bash. I seem bash syntax error near unexpected token then' to have hit a syntax error which I've narrowed down to being in this bit of code. randno4=($RANDOM % 100001) upper_limit4=$(echo "scale=10; 1*75.3689"|bc) lower_limit4=$(echo "scale=10; 1*75.1689"|bc) range4=$(echo "scale=10; $upper_limit4-$lower_limit4"|bc) t_twall=`echo "scale=10; ${lower_limit4}+${range4}*${randno3}/100001" |bc` echo "$t_twall" Does anyone know why I the below output and not a value between 75.3689 and 75.1689 as that is what I would be expecting? (standard_in) 1: syntax error bash syntax-error share|improve this question edited Nov 25 '14 at 19:26 asked Nov 25 '14 at 19:24 Reluctant_Linux_User 192110 1 randno4=($RANDOM % 100001) is not arithmetic evaluation. That will create a randno4='([0]="25649" [1]="%" [2]="100001")' array. Perhaps you meant randno4='$(($RANDOM % 100001))'? –Etan Reisner Nov 25 '14 at 19:27 1 That first line is fine. It just doesn't do what you think it does. Run that line and then run declare -p randno4. Then try echo "$randno4" vs. echo "${randno4[1]}". –Etan Reisner Nov 25 '14 at 19:28 3 I believe the actual err
here for a quick overview of the site Help Center Detailed answers to any
Bash Syntax Error Near Unexpected Token Do'
questions you might have Meta Discuss the workings and policies of bash syntax error near unexpected token newline' this site About Us Learn more about Stack Overflow the company Business Learn more about hiring bash syntax error unexpected end of file developers or posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer http://stackoverflow.com/questions/27134988/standard-in-1-syntax-error-in-bash-script 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 BC returns syntax error up vote 0 down vote favorite #!/bin/bash http://unix.stackexchange.com/questions/162100/bc-returns-syntax-error cd ~/simplesim-3.0/benchmarks INSTS=$(grep "sim_num_insn" ./anagram.txt | awk '{print $2}'); IL1_ACCESSES=$(grep "il1.accesses" ./anagram.txt | awk '{print $2}'); IL1_MISSRATE=$(grep "il1.miss_rate" ./anagram.txt | awk '{print $2}'); DL1_ACCESSES=$(grep "dl1.accesses" ./anagram.txt | awk '{print $2}'); DL1_MISSRATE=$(grep "dl1.miss_rate" ./anagram.txt | awk '{print $2}'); IL2_ACCESSES=$(grep "il2.accesses" ./anagram.txt | awk '{print $2}'); IL2_MISSRATE=$(grep "il2.miss_rate" ./anagram.txt | awk '{print $2}'); DL2_ACCESSES=$(grep "dl2.accesses" ./anagram.txt | awk '{print $2}'); DL2_MISSRATE=$(grep "dl2.miss_rate" ./anagram.txt | awk '{print $2}'); IL1_API=`echo "scale=4;$DL1_ACCESSES/$INSTS" | bc -l`; DL1_API=`echo "scale=4;$IL1_ACCESSES/$INSTS" | bc -l`; IL2_API=`echo "scale=4;$IL2_ACCESSES/$INSTS" | bc -l`; DL2_API=`echo "scale=4;$DL2_ACCESSES/$INSTS" | bc -l`; DL1_P=`echo "scale=4;$DL1_MISSRATE*5.0" | bc -l`; IL1_P=`echo "scale=4;$IL1_MISSRATE*5.0" | bc -l`; IL2_P=`echo "scale=4;$IL2_MISSRATE*40.0" | bc -l`; DL2_P=`echo "scale=4;$DL2_MISSRATE*40.0" | bc -l`; DL1_PENALTY=`echo "scale=4;$DL1_P*$DL1_API" | bc -l`; IL1_PENALTY=`echo "scale=4;$IL1_P*$IL1_API" | bc -l`; IL2_PENALTY=`echo "scale=4;$IL2_P*$IL2_API" | bc -l`; DL2_PENALTY=`echo "scale=4;$DL2_P*$DL2_API" | bc -l`; CPI_a=`echo "scale=4;$DL1_PENALTY+$DL2_PENALTY" | bc -l`; CPI_b=`echo "scale=4;$IL1_PENALTY+1.0" | bc -l`; CPI_c=`echo "scale=4;$IL2_PENALTY+$CPI_b" | bc -l`; #CPI=`echo "scale=4;$UL1_P+1.0+$UL2_P" | bc`; CPI=`echo "scale=4;$CPI_a+$CPI_c" | bc`; echo $CPI I am running this script. I checked that the va
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/45781/shell-script-fails-syntax-error-unexpected 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://www.unix.com/shell-programming-and-scripting/141599-bc-giving-error-standard_in-2-parse-error.html 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 Shell syntax error script fails: Syntax error: “(” unexpected up vote 31 down vote favorite 7 I've been working on a script that automates setting up a development environment for Raspberry Pi development (step by step details that work are here). The script is linked in that article but convenience you can find it here also. Now when run this script install and sets up the environment without error but you have to enter your sudo password more than bash syntax error once due to sudo's time-out value by default. So I started experimenting by removing all the sudo lines and running the whole script via sudo at the command line like so: kemra102@ubuntuvm:~$ sudo ./pi_dev_env_install.sh This works fine as expected and gets most of the way through until this point: ./pi_dev_env_install: 68: ./pi_dev_env_install.sh: Syntax error: "(" unexpected Now this line worked fine previously when not running the whole script with sudo. There is nothing about this line running as sudo that should stop it working to my knowledge, does anyone have any ideas? bash shell ubuntu shell-script share|improve this question edited Aug 18 '12 at 12:08 Gilles 369k666681119 asked Aug 18 '12 at 11:37 kemra102 4681613 The shebang is really in line 9? Due to Ubuntu's DashAsBinSh affinity I suspect your script is interpreted by dash instead of bash. Try to move the shebang in line 1. –manatwork Aug 18 '12 at 11:45 According to that article calling /bin/bash directly instead of /bin/sh will; correctly use bash instead of dash so that should not be an issue as I understand it. I can still move the shebang of course, but that doesn't really explain as to why it works when you don’t sudo the whole script. –kemra102 Aug 18 '12 at 11:50 add a comment| 5 Answers 5 active oldest votes up vote
Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here. Search Forums Show Threads Show Posts Tag Search Advanced Search Unanswered Threads Find All Thanked Posts Go to Page... unix and linux commands - unix shell scripting bc giving error: (standard_in) 2: parse error Shell Programming and Scripting Page 1 of 2 1 2 > Thread Tools Search this Thread Display Modes #1 08-04-2010 manishma71 Registered User Join Date: Jun 2009 Last Activity: 14 December 2010, 3:19 AM EST Posts: 18 Thanks: 1 Thanked 0 Times in 0 Posts bc giving error: (standard_in) 2: parse error Below part of script, is working fine sometimes and gives error sometime. I am doing float operations, checking if x > y. ##########CODE########## Code: THRESHOLD="1.25" ratio=$( echo "scale=2; ${prev}/${current}" | bc ) if [ $(echo "${ratio} > ${THRESHOLD}" | bc ) -eq 1 ]; then split_date=`echo ${line} | cut -d, -f2` fi ######################## below is the error i am getting - Code: script/split_checks.sh: line 62: [: -eq: unary operator expected (standard_in) 2: parse error (standard_in) 1: parse error Thanks, Manish ---------- Post updated at 10:47 AM ---------- Previous update was at 10:41 AM ---------- i have put checks to make sure that prev & current are non-zero values.... Last edited by pludi; 08-04-2010 at 02:56 AM.. Remove advertisements Sponsored Links manishma71 View Public Profile Find all posts by manishma71 #2 08-04-2010 pravin27 Advisor Join Date: Sep 2009 Last Activity: 7 September 2016, 8:47 AM EDT Location: ./India/Bangalore Posts: 1,271 Thanks: 70 Thanked 299 Times in 290 Posts change Code: if [ $(echo "${ratio} > ${THRESHOLD}" | bc ) -eq 1 ]; the to Code: if [ ${ratio} > ${THRESHOLD} ]; then Remove advertisements Sponsored Links pravin27 View Public Profile Find all posts by pravin27 #3 08-04-2010 agn Registered User Join Date: Feb 2008 Last Activity: 6 August 2013, 7:49 AM EDT Posts: 345 Thanks: 0 Thanked 21 Times in 21 Posts Instead of Code: if [ $(echo "${ratio} > ${THRESHOLD}" | bc ) -eq 1 ]; then try Code: if [ $ratio -le $THRESHOLD ]; then The reason yo