# Function throwing an error

**URL:** <https://community.unix.com/t/function-throwing-an-error/344187>\
**Category:** Shell Programming and Scripting\
**Created:** [July 4, 2014, 2:06am UTC](https://community.unix.com/t/function-throwing-an-error/344187 "2014-07-04T02:06:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![swasid](https://community.unix.com/letter_avatar/swasid/32/6_22734026db12803ebb3e059622ac3534.png) [@swasid](https://community.unix.com/u/swasid)\
**Post date:** [July 4, 2014, 2:06am UTC](https://community.unix.com/t/function-throwing-an-error/344187/1 "2014-07-04T02:06:34Z")

</div>

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:

```nohighlight
#!/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:

```nohighlight

#!/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:

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

```

Please help

---

<div class="post-metadata">

**Author:** ![SriniShoo](https://community.unix.com/letter_avatar/srinishoo/32/6_22734026db12803ebb3e059622ac3534.png) [@SriniShoo](https://community.unix.com/u/SriniShoo)\
**Post date:** [July 4, 2014, 2:48am UTC](https://community.unix.com/t/function-throwing-an-error/344187/2 "2014-07-04T02:48:40Z")

</div>

what flavor of unix you are trying this in

---

<div class="post-metadata">

**Author:** ![swasid](https://community.unix.com/letter_avatar/swasid/32/6_22734026db12803ebb3e059622ac3534.png) [@swasid](https://community.unix.com/u/swasid)\
**Post date:** [July 4, 2014, 3:04am UTC](https://community.unix.com/t/function-throwing-an-error/344187/3 "2014-07-04T03:04:21Z")

</div>

Am running this on AIX 5

---

<div class="post-metadata">

**Author:** ![SriniShoo](https://community.unix.com/letter_avatar/srinishoo/32/6_22734026db12803ebb3e059622ac3534.png) [@SriniShoo](https://community.unix.com/u/SriniShoo)\
**Post date:** [July 4, 2014, 3:08am UTC](https://community.unix.com/t/function-throwing-an-error/344187/4 "2014-07-04T03:08:43Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![Scrutinizer](https://community.unix.com/user_avatar/community.unix.com/scrutinizer/32/1216_2.png) [@Scrutinizer](https://community.unix.com/u/Scrutinizer)\
**Post date:** [July 4, 2014, 3:15am UTC](https://community.unix.com/t/function-throwing-an-error/344187/5 "2014-07-04T03:15:20Z")

</div>

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

```nohighlight
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:

```nohighlight
/path/to/script1.sh

```

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

```nohighlight
script1.sh

```

you can also use:

```nohighlight
bash script1.sh

```

---

<div class="post-metadata">

**Author:** ![clx](https://community.unix.com/letter_avatar/clx/32/6_22734026db12803ebb3e059622ac3534.png) [@clx](https://community.unix.com/u/clx)\
**Post date:** [July 4, 2014, 4:36am UTC](https://community.unix.com/t/function-throwing-an-error/344187/6 "2014-07-04T04:36:28Z")

</div>

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

```nohighlight
dos2unix file

```

---

<div class="post-metadata">

**Author:** ![Kibou](https://community.unix.com/user_avatar/community.unix.com/kibou/32/1665_2.png) [@Kibou](https://community.unix.com/u/Kibou)\
**Post date:** [July 5, 2014, 4:59am UTC](https://community.unix.com/t/function-throwing-an-error/344187/7 "2014-07-05T04:59:35Z")

</div>

> [@scrutinizer](#):
>
> How do you execute test1.sh? If for example, you execute the script like
> 
> ```plaintext
> 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:
> 
> ```plaintext
> /path/to/script1.sh
> 
> ```
> 
> or if it is in your search path, you can use
> 
> ```plaintext
> script1.sh
> 
> ```
> 
> you can also use:
> 
> ```plaintext
> bash script1.sh
> 
> ```

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.

---

<div class="post-metadata">

**Author:** ![Scrutinizer](https://community.unix.com/user_avatar/community.unix.com/scrutinizer/32/1216_2.png) [@Scrutinizer](https://community.unix.com/u/Scrutinizer)\
**Post date:** [July 5, 2014, 5:41am UTC](https://community.unix.com/t/function-throwing-an-error/344187/8 "2014-07-05T05:41:58Z")

</div>

@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](http://www.gnu.org/software/bash/manual/html_node/Bash-POSIX-Mode.html)

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