script sourcing problem (ksh)


 
Thread Tools Search this Thread
# 1  
Bug script sourcing problem (ksh)

I have a script "abc.sh" in /tmp which has exit 0 as its last line

when I run this script from /tmp/xyz/def.sh script as

Code:
. ../abc.sh

then the script executes but the control doesn't return to def.sh script for subsequent commands in def.sh

but if I invoke the abc.sh from inside the def.sh as

Code:
../abc.sh

then the control

Also

if the def.sh script is in /tmp directory and I invoke the abc.sh script from def.sh script as

Code:
. ./abc.sh

then the control returns back to def.sh with out problems

isn't it strange?

Quote:
I mean . ./abc.sh works but . ../abc.sh doesn't
I am trying to understand the script sourcing and this is breaking my head.

Please help

Thank you
# 2  
Quote:
Originally Posted by rakeshou
isn't it strange?
No, it's doing exactly what it's told. "exit 0" terminates the process. When you call it ../abc.sh it is running as a child process and correctly terminates.

When you run it using . it runs in the same process and happily terminates that.
# 3  
I am trying to figure out this sourcing stuff, but can't find documentation for it online.

Where does this look

. ../script.sh (parent directory?)

versus this

. ./script.sh (current directory?)

What does the initial '.' mean? Is it the command to look for something?
# 4  
And is it possible to run a script that calls another script 2 directories above, but still refer to a child directory of the original one?

top directory
|
V
SBCS directory
|
V
Version directory (main script that calls generic script from top directory and needs to run stuff from Tar directory)
|
V
Tar directory (where untarred scripts/files are)
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #492
Difficulty: Medium
Transpilers are source-to-source compilers that directly produce assembly or machine code,
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Resume parent shell after sourcing another script

#! /bin/ksh #first.sh echo "b4 set exit as return" alias exit=return echo "call second" . ./second.sh echo "after second" #. ./third.sh unalias exit echo "ho lanciato il terzo" =================// #second.sh echo "in scond" exit ==============// the above code works in k... (2 Replies)
Discussion started by: mprakasheee
2 Replies

2. Shell Programming and Scripting

Sourcing Env file with eval works with ksh but not BASH

Hi, I am running this on Redhat 5.10 I have a simple test script called test.sh which has the following contents and it uses the BASH shebang. ------------------------------------------------------------- #!/bin/bash eval `/tmp/filereader.pl /tmp/envfile.txt` echo "TESTPATH=$TESTPATH" ... (28 Replies)
Discussion started by: waavman
28 Replies

3. UNIX for Advanced & Expert Users

Dot sourcing differences in ksh, AIX vs Linux vs Solaris

Why does dot sourcing of ksh functions behave so differently between AIX, Solaris, and Linux? How can I make Linux behave the way I want in the test I show below? I have a library of interdependent functions I have developed and use in ksh in AIX. They also run in Solaris. Now I am migrating... (9 Replies)
Discussion started by: charles_n_may
9 Replies

4. Shell Programming and Scripting

Sourcing variables from another script

My manager required that i keep the hostnames and username and password in a separate file when creating my sftp script. (Don't mention passwords and sftp...I've talk to him about this several times) I have a list of hostnames that have to be read in a loop in my main script. I don't know... (3 Replies)
Discussion started by: MJCreations
3 Replies

5. UNIX for Dummies Questions & Answers

problem in Executing script in ksh

Hi, I am in ksh. below mentioned 3 commands I executed at command prompt & got the expected results. csh source csh_infa <special command> Now I have to do this in the script in ksh. I entered it as it is. #!/bin/ksh csh source csh_infa <special command> Now after... (1 Reply)
Discussion started by: girish_kanak
1 Replies

6. Shell Programming and Scripting

$1 stays set after sourcing shell script.

ok, so I have a shell script that can be called using the first argument ($1) or not. This argument is a word (Tim for example) and not an actual flag (-x for example). If I call the script with an argument and call the same script without one, it believes that I provided an argument. Note here... (2 Replies)
Discussion started by: mrwatkin
2 Replies

7. UNIX for Dummies Questions & Answers

Problem with xterm & tcsh & sourcing a script in a single command

Hi friends, I have a script that sets the env variable path based on different conditions. Now the new path variable setting should not done in the same terminal or same shell. Only a new terminal or new shell should have the new path env variable set. I am able to do this only as follows: >cd... (1 Reply)
Discussion started by: sowmya005
1 Replies

8. UNIX for Dummies Questions & Answers

word too long..problem while sourcing .cshrc

I am setting my PATH & LD_LIBRARY_PATH through .cshrc file while sourcing it on a old shell i am getting the error word too long .and the changes which i anm doing doesn't get updated . i am in a multi user environment so the only way to do the changes only for my shell is to do it that way. ... (1 Reply)
Discussion started by: mobydick
1 Replies

9. Shell Programming and Scripting

Maintain full path of a script in a var when sourcing it from a different script

Hi All, I've searched through the forum for a solution to this problem, but I haven't found anything. I have 2 script files that are in different directories. My first script, let's call it "/one/two/a.sh" looks like this: #!/bin/sh IN_DIR=`dirname $0` CUR_DIR=`pwd` cd $IN_DIR... (4 Replies)
Discussion started by: mrbluegreen
4 Replies

10. Shell Programming and Scripting

Ksh problem in script

Hi I made a small script which uses ksh. When i run the script then i get the following error However when i run each of the commands on the commandline they get executed and provide the desired output. i cant figure out why the script is not running. Kindly Help Thanks in... (3 Replies)
Discussion started by: PradeepRed
3 Replies

Featured Tech Videos