Function throwing an error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Function throwing an error
# 1  
Old 07-04-2014
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:

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

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

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

Please help
# 2  
Old 07-04-2014
what flavor of unix you are trying this in
# 3  
Old 07-04-2014
Am running this on AIX 5
# 4  
Old 07-04-2014
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
# 5  
Old 07-04-2014
How do you execute test1.sh? If for example, you execute the script like
Code:
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:
Code:
/path/to/script1.sh

or if it is in your search path, you can use
Code:
script1.sh

you can also use:
Code:
bash script1.sh


Last edited by Scrutinizer; 07-04-2014 at 06:00 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 07-04-2014
Also If you created the files in windows, don't forget to change the line endings.
Easy way is
Code:
dos2unix file

# 7  
Old 07-05-2014
Quote:
Originally Posted by Scrutinizer
How do you execute test1.sh? If for example, you execute the script like
Code:
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:
Code:
/path/to/script1.sh

or if it is in your search path, you can use
Code:
script1.sh

you can also use:
Code:
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Prustat throwing error only in zones not in global

Hi, Prustat is throwing error only in zones. But it is working fine in global. dtrace: invalid probe specifier /* ** The following is a trimmed version of two seperate DTrace scripts: ** ** socketsnoop.d - snoop TCP network socket traffic by process. ** This is intended to identify the... (3 Replies)
Discussion started by: Sumanthsv
3 Replies

2. UNIX for Beginners Questions & Answers

Make throwing error while compiling python3.6 on Solaris10

Hi, I have downloaded gzipped source tarball of python3.7. I have tried to compile like below, ./configure --prefix=/directory Compiling seems to be ok..But when running make all..Getting too many missing initializer warnings /python3.6/Python-3.6.0/Modules/_cursesmodule.c: At top level:... (1 Reply)
Discussion started by: Sumanthsv
1 Replies

3. Shell Programming and Scripting

For Loop throwing error

Hello Gurus, I am writing one script at linux. The logic is There is a find command which will find some specific files daily and store at a variable Then echo that variable . Now when I am trying to read the variable by using for loop it is throwing error as below:cat: CKDT.dat: No such... (5 Replies)
Discussion started by: pokhraj_d
5 Replies

4. Shell Programming and Scripting

awk--throwing an error

Hi all, I have below code sqlplus -s ext/exo@TIS << EOF whenever sqlerror exit failure rollback; set echo off set head off set serveroutput on set termout on set trimspool on SPOOL $SPOOL_FILE select 'ROWS '|| ' '||decode((count(Part_no)),0,'With greater values not... (3 Replies)
Discussion started by: Kiransagar
3 Replies

5. Shell Programming and Scripting

Tr--translate is throwing an error

Dear all, I would like to count the no;of word "INFORMATION" in a file called alt.lst and output to a unix variable INFORMATION.so to do this I wrote the below code INFORMATION=echo 'INFORMATION' | tr -cs 'A-Za-z' '\n' < /app/tisq005/01/home/tisq005b/scripts/alt.lst | grep -c "INFORMATION"... (2 Replies)
Discussion started by: Kiransagar
2 Replies

6. Shell Programming and Scripting

POCO install throwing error

All , I am trying to install POCO lib on Solaris server. When I do make -s,I am getting the following error. make: Fatal error in reader: Makefile, line 10: Unexpected end of line seen Few of the content: # # Makefile # # The global Makefile for POCO # #sinclude config.make ... (0 Replies)
Discussion started by: prasperl
0 Replies

7. Shell Programming and Scripting

for loop throwing an error

Hi Guys, I am trying a simple for loop which is throwing an error. Below is my code: #/bin/sh set -A array "are" "you" "there"; for ( i = 0 ; i < ${#array} ; i++ ) do echo ${array} done I am getting this error tci001wasd02 $ sh -vx array_for.sh #/bin/sh set -A array "are"... (6 Replies)
Discussion started by: mac4rfree
6 Replies

8. Red Hat

formating a USB which is throwing error write delayed

Hello, while i was saving a web file directing on to usb location there was some network problem which result in error WRITE DELAYED on windows xp. so pen drive is not getting completely formated(show as Windows was unable to complete format).From then onwords it is not allowing to copy... (0 Replies)
Discussion started by: amarnathbasis8
0 Replies

9. UNIX for Dummies Questions & Answers

forcefully throwing error : unix script

how can i make one script fail if some condition is not satisfied.i m writing if ..else logic in script.i need some standard command to do that ,, (1 Reply)
Discussion started by: dr46014
1 Replies

10. UNIX for Dummies Questions & Answers

Remote login/copy command throwing an error

Hi We had 3 server -hp112and hp146 here hp112 is production server and hp146 is staging server used for load. when i am trying to run follwing command rcp abc hp112:/dnbusr1/gbid/gbid02 it's trowing an error :- remshd: Login incorrect. But same command is working wise versa - rcp abc... (1 Reply)
Discussion started by: ashish_panpalia
1 Replies
Login or Register to Ask a Question