weird korn shell script


 
Thread Tools Search this Thread
Operating Systems AIX weird korn shell script
# 1  
Old 07-12-2010
Question weird korn shell script

here is the one of the scripts:

script1.ksh
Code:
function haha
{
  print "calling haha"
  exit
}

script2.ksh
Code:
. script1.ksh
haha | tee -a /dev/null
print "i am script 2"

after launching the script2, the result:
---------------------------------------------
Code:
calling haha
i am script 2

would be presented, could someone please tell me why the "exit" statement NOT working properly?

Last edited by pludi; 07-12-2010 at 04:01 AM.. Reason: code tags, please...
# 2  
Old 07-12-2010
Because you are sending the output to null. just remove the pipe and tee cmd and you will get it

script1.ksh
Code:
function haha
{
  print "calling haha"
  exit
}

script2.ksh
Code:
. script1.ksh
haha 
print "i am script 2"

# 3  
Old 07-12-2010
thanks for your reply, and what you pointed is what i want to know, could you give me a hint please
# 4  
Old 07-12-2010
tee command can be placed anywhere in a pipe to check what the output looks like at a certain point. So basically you have directed the output of function haha to a file instead of standard output and thus the execution of rest of the commands continues as normally
# 5  
Old 07-12-2010
due to the pipe line, the function ran in a sub (child) process so the "exit" only exited the sub process.
This User Gave Thanks to binlib For This Post:
# 6  
Old 07-12-2010
I agree with binlib.

if you combine the two scripts the "exit" will behave as you expect.

Code:
#!/bin/ksh
#script2.ksh
function haha
{
  print "calling haha"
  exit
}

haha 
print "i am script 2"

./script2.ksh
calling haha

# 7  
Old 07-14-2010
thanks for all~!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Weird Exit Status of shell script

I have a script named check which will read the content of a file and check wether those files exist in the current directory. If so it will have the exit status of 0, otherwise it will have 1. check script: #!/bin/bash if ; then #Check there is enough command line parameters. exit 1... (2 Replies)
Discussion started by: Ray Sun
2 Replies

2. Shell Programming and Scripting

share a shell script which can replace weird characters in directory or file name

I just finish the shell script . This shell can replace weird characters (such as #$%^@!'"...) in file or directory name by "_" I spent long time on replacing apostrophe in file/directory name added: 2012-03-14 the 124th line (/usr/bin/perl -i -e "s#\'#\\'#g" /tmp/rpdir_level$i.tmp) is... (5 Replies)
Discussion started by: begonia
5 Replies

3. Shell Programming and Scripting

pass null value to sql script from korn shell script

There are 4 parameters that I have to pass from korn shell to sql script. 1) I have to check if $1 , $2 , $3 and $4 are null values or not . How can I do that ? 2) Once its determined that these values are null (in the sense they are empty) how can I pass null values to sql script... (11 Replies)
Discussion started by: megha2525
11 Replies

4. Shell Programming and Scripting

Weird problem in my shell script,please help me!!!

sqlLogftp_mov=$LOGDIR/logftp_mov_$mydate.log sqlplus -s $ORAUSER << EOF > $sqlLogftp_mov SET SERVEROUT ON @/$SCRIPTDIR/rep_comm_ext_tbl_load.sql EOF retorno=0 cnt=`grep -q 'ORA-' $sqlLogftp_mov | wc -l` if ; then retorno=1 echo 'Failure' sendEmailFalha exit 1 fi if ; then echo... (8 Replies)
Discussion started by: shyamaladevi
8 Replies

5. Homework & Coursework Questions

Korn Shell Script

1. The problem statement, all variables and given/known data: Write a korn shell script with an alfanumeric string as argument. The script lists the file's names in the current directory that contain the given string as substring and that can be read and written. 2. Relevant commands, code,... (3 Replies)
Discussion started by: burm
3 Replies

6. Shell Programming and Scripting

Korn Shell Script

I have to solve some exercises in Korn Shell, but i'm having some problems. For example: Write a korn shell script with an alfanumeric string as argument. The script lists the file's names in the current directory that contain the given string as substring and that can be read and written. I... (3 Replies)
Discussion started by: burm
3 Replies

7. AIX

Help with Korn Shell script

I have this Korn shell script that runs via a cron entry. It runs in a loop "watching" a specific file system for files with a certain name. The file system that it is watching is an upload file system for an FTP server. When files that are the correct name come in, it takes the extension of the... (1 Reply)
Discussion started by: heprox
1 Replies

8. UNIX Desktop Questions & Answers

korn shell script

hi all i am writing the korn shell script. i have a SQL script which gives me the folowing output DSA.WLG.20050713211544.20051025.20050713211544 28991 1130198400 DSA.WLG.20050713211544.20051025.20050713211544 25881 1130198400 DSA.WLG.20050711210100.20051025.20050711210100 25881 ... (3 Replies)
Discussion started by: pavan_test
3 Replies

9. UNIX for Dummies Questions & Answers

korn shell script

hello., i have 2 files.. 1 file is in this folder /home/test/ssk/DSA.WLG.20050713211544.20050710.20050713211544 (this part) other file is in this folder /home/kk/dev/DSA.WLG.20050711210100.20050710.20050711210100 ... (1 Reply)
Discussion started by: pavan_test
1 Replies

10. Shell Programming and Scripting

Multiple su - in Korn Shell script

i am trying to do something like this : #!/bin/ksh # Change to the userid user1 su - user1 #Issue the command to change directory and list files cd /home/user1/ ls -lrt exit #Come out of the user1 to root again #change to user 2 su - user2 cd /home/user2/ ls -lrt... (2 Replies)
Discussion started by: furrari
2 Replies
Login or Register to Ask a Question