Function throwing an error

Hi All

I have two shell scripts where the second is getting invoked from the first. E.g.

test1.sh and test2.sh Within test1, the code is something like this:

#!/bin/bash

. test2.sh

usage() {
  echo "..."
  echo "....."
}
SRC=$1
DEST=$2

case "$3" in
  tran) doTran ;;
   *) usage && exit 1 ;;
esac

and within test2.sh, the code looks like this:


#!/bin/bash

doTran() {
  src=(
    "sample1*.gz" 
    "sample2*.gz"
  )
  target=(
   "SAMPLE1.csv"
   "SAMPLE2.csv"
  )

  trigger "tran"
}

When the main script test1.sh is executed, it's throwing the below error:

test2.sh[3]: 0403-057 Syntax error at line 4 : `(' is not expected.

Please help

what flavor of unix you are trying this in

Am running this on AIX 5

I dont see any issues in test1.sh / test2.sh
I ran the above code as it is without any issues except I replaced trigger with echo

How do you execute test1.sh? If for example, you execute the script like

sh script1.sh 

then you are bypassing the shebang on line one and script does not get executed with bash , but rather the default POSIX shell ( /usr/bin/sh ). If you want to use bash for that script, then you either need to make it executable with chmod and use:

/path/to/script1.sh

or if it is in your search path, you can use

script1.sh

you can also use:

bash script1.sh
1 Like

Also If you created the files in windows, don't forget to change the line endings.
Easy way is

dos2unix file

That's right. I could reproduce what Scrutinizer said on my Linux as well.

When executed with sh it gave me an error because it bypasses the shebang.

But I came up with a question. Is there really a binary for sh in /usr/bin/sh in AIX? Because in Linux there's no executable or binary file for sh . sh is an internal behaviour of bash . The only executable of sh is a symbolic link to bash .

Another question, briefly, what are the = ( ) for?

Thanks.

@Kibou : That does not really matter. on AIX there are hard links from /usr/bin/sh /usr/bin/ksh , /bin/sh and /bin/ksh to the same ksh .

On many linux distribution there is a symbolic link from /bin/sh to /bin/bash . On derivatives of Debian this points to dash .

When it is symbolic link to bash and /bin/sh is called then bash acts as if it was called with the --posix option...
Bash Reference Manual: Bash POSIX Mode

=( ) is used to assign values to arrays...

1 Like