I searched everywhere for the answer to this question. I have an array in my shell script, but when I run it, I get this error: "(" unexpected
"(" unexpected
What am I doing wrong here:
array=( 1 2 3 4 5 )
I am using Ubuntu 11.10
You are using a script with /bin/sh , not /bin/bash . There are no arrays in sh .
/bin/sh
/bin/bash
sh
choroba@cyan ~$ /bin/sh $ a=( 1 2 3 ) /bin/sh: Syntax error: "(" unexpected
do you use bash?
$ bash --version GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin11) Copyright (C) 2007 Free Software Foundation, Inc. $ array=( 1 2 3 4 5 ) $ echo ${array[1]} 2 $
Also sometime this is due to extra space:
array = (1 2 3 4)
wrong. It should be:
array=(1 2 3 4)
Try specifying the word bash when running the script as follows:
bash
$ bash script.sh
Source: https://habr.com/ru/post/1385482/More articles:https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1385477/access-to-the-path-is-denied&usg=ALkJrhgO8F6dMMP9eOB9m2WTknrjOH21zwString regularization using regular expression in javascript - javascriptPython re.sub: ignore backlinks in replacement string - pythonHow to delete documents a month ago - luceneHow to import / read data from a csv file (comma separated) in coldfusion - coldfusionWhy does the String type require the Hibernate JPQL type - hibernateSecuring a PHP file using htaccess - securityhow to create jQuery loading bar? (for example, those used on flash sites) - javascriptCSV for multidimensional array with ColdFusion - arraysReading the entire entry from the socket continuously - javaAll Articles