Quitting from a script, either sourced or not


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Quitting from a script, either sourced or not
# 8  
Old 05-18-2010
Quote:
Originally Posted by curleb
Using return should be analogous to exit in both cases...without the pesky side-effect of killing the parent.

What exactly is the issue? Have you traced the process with set -x? [embed set -x into each function in use to capture the flow across each subprocess...]
It could be, but not necessarily.

Quote:
Originally Posted by IEEE Std 1003.1-2008
The return utility shall cause the shell to stop executing the current function or dot script. If the shell is not currently executing a function or dot script, the results are unspecified.
From Shell Command Language

Regards,
Alister

---------- Post updated at 12:55 PM ---------- Previous update was at 12:41 PM ----------

Quote:
Originally Posted by MadMage
The main purpose of the script is to set some environment variables, so I MUST source it.
Well, if you must source and it must not kill the parent shell, it cannot use exit. Refactor the script so that it does not require it.

If you want to get really ugly, you could wrap the sourcing with something like:
Code:
exit() { return $1; }
. script
unset -f exit

Although that will not work if the exit calls occur within a function (the sourced function will return but the sourced script will continue executing).

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Preloading open() for files sourced by tcsh

I am overriding the file open system calls (open, open64, fopen, fopen64, freopen, freopen64) in a dynamic library and setting LD_PRELOAD to point to that library. Here is a sample script I'm testing this on - #!/bin/tcsh source testcsh1.csh source testbash1.sh On RHEL 5.7 (tcsh 6.14.00), the... (2 Replies)
Discussion started by: endgame
2 Replies

2. Shell Programming and Scripting

Return: can only `return' from a function or sourced script

Not sure where the problem is. I can run the script without any issue using the following command. . /opt/app/scripts/cdc_migration.sh But it fails with the below error when I try it this way /opt/app/scripts/cdc_migration.sh /opt/app/scripts/cdc_migration.sh: line 65: return: can only... (1 Reply)
Discussion started by: svajhala
1 Replies

3. Shell Programming and Scripting

Problem in quitting/exiting from sqlplus

Hello, This is my first post and I would be very thankful if you can help me. I've already searched in the forum and I've found a very similar thread in wich my problem is solved, but the thread is closed and the solution given in it doesn't work in my shell: 153194-problem-quitting-sqlplus ... (11 Replies)
Discussion started by: JuanPerez
11 Replies

4. Shell Programming and Scripting

Error Installing Env::Sourced

Hello, I am trying to install Env::Sourced and i get the following error. sh: source: not found sh: include.sh: not found Unable to determine your shells source program, typically 'source' or '.' How can i overcome this? Best Regards, Christos (3 Replies)
Discussion started by: chriss_58
3 Replies

5. Shell Programming and Scripting

problem in quitting from sqlplus

Hi all, I have a scenario where im connecting to sqlplus executing a query,redirecting the output to a file and manipulating the file MY CODE IS AS FOLLOWS sqlplus -s /nolog << EOF > $UTILITIES_HOME/temp/analyze.temp.log & set linesize 3000 set trimspool on set pagesize... (2 Replies)
Discussion started by: niteesh_!7
2 Replies

6. Shell Programming and Scripting

Quitting a bash script... any alternatives to exit?

Folks, Below is a basic synopsis of the problem. I have a script that I need to check for some env vars and fail (exit the script) if they are not there. At the same time I need to set some default env vars. To do this I must run the script from the parent shell or source the script. Doing... (3 Replies)
Discussion started by: bashN00b
3 Replies

7. Shell Programming and Scripting

KSH - Sourced file location

The sample scripts below, I am looking for the location of the sourced b.sh file. The b.sh file is source by multiple files, so it is not feasible to rely on a "global" variable or passed argument. Is there any way to determine the location of b.sh within b.sh? a.sh #!/bin/ksh echo "a:... (11 Replies)
Discussion started by: Al262
11 Replies

8. Shell Programming and Scripting

Exit from sourced script

Hello, I have written a script (say chld.sh). its structure is as follows: ------------------------ #!/bin/sh usage() { echo "chld.sh <param1> <param2>" exit 0 } chk_param_1() { case $param1 in c) export PATH=$PATH:/home_a/bin/execs;; d) export... (2 Replies)
Discussion started by: angad.makkar
2 Replies

9. OS X (Apple)

which file is sourced by bash on login (Mac OS X 10.5.3)?

Hi: So my current Python (2.52) rig is not working as intended. "echo $PATH" in bash gives me 'X'" that's not what i want, so i need to change my path. To do that, there appeared to be four choices (all in my ~/ directory--note: I'm root, it's my Mac, but i'm in a user account): .profile... (2 Replies)
Discussion started by: Alex_Land
2 Replies

10. Solaris

Emacs changes the term colors after quitting

Ok. So I've finally compiled the latest version of GNU emacs on Solaris 5.8. I've set putty up so that it sets TERM=xtermc. emacs now has syntax highlighting. The problem is, whenever I quit emacs, it changes the screen colors. The background is now the same as the color of the minibuffer. It... (1 Reply)
Discussion started by: m9dhatter
1 Replies
Login or Register to Ask a Question