Visit Our UNIX and Linux User Community


Exit the shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Exit the shell script
# 1  
Old 09-06-2013
Exit the shell script

Hi,

suppose my script is sample.sh
i have to run using '. ./sample.sh'
as . ./script file always executes the script in my parent shell.
when my sample.sh contains exit command .. my environment is getting closed as am executing in the parent shell ...
please suggest me how can i use exit command when am executing a shell script using '. ./' format.
# 2  
Old 09-06-2013
. ./script is equivalent to typing the commands in script one by one on the terminal.

This method of invoking (or dotting) a file is used when we need to export a lot of parameters for use by current shell.

If you want to use exit and don't want to exit the terminal then "execute" the script by using ./script after checking the execute permission on the script.

If you have any particular reason to invoke the script like parameter export scenario mentioned above, separate those statements alone into a separate script and invoke it using the dot space format.
# 3  
Old 09-06-2013
Hi Krishmaths,

Thanks for your quick response..
can you elaborate more on ./script
my script name is logproc, as i dont want to exit my terminal should I execute as
./logproc
I tried this but following error occured
-bash: ./logproc.sh: No such file or directory.
Please let me know how can i execute my script without exiting the terminal(. ./filename execution is mandatory)

Last edited by Franklin52; 09-06-2013 at 08:09 AM.. Reason: fixed tags
# 4  
Old 09-06-2013
The return command can be used instead of exit if the script is sourced (invoked using . ./script.sh).
This User Gave Thanks to cero For This Post:
# 5  
Old 09-06-2013
If your script name is logproc either navigate to the directory where the script is available and execute as ./logproc or execute using absolute path /my/dir1/logproc (Replace /my/dir1) with the directory name where the script is available.

If the script name has a .sh extension remember to include that as well while executing.
# 6  
Old 09-06-2013
Quote:
Originally Posted by krishmaths
If your script name is logproc either navigate to the directory where the script is available and execute as ./logproc or execute using absolute path /my/dir1/logproc (Replace /my/dir1) with the directory name where the script is available.

If the script name has a .sh extension remember to include that as well while executing.
And, be sure that the file has been made executable:
Code:
chmod +x ./script.sh


Previous Thread | Next Thread
Test Your Knowledge in Computers #933
Difficulty: Medium
Microcontrollers operating within embedded systems (such as the Raspberry Pi, Arduino, and other similar systems) always have internal hardware to keep track of time.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to continue shell script after exit 0?

Hi, I am writing a shell script where I am sourcing other shell script in that script I have mention exit 0 due to that it is not continue the first script. Except doing any changes to source script is there any way I can continue the my first script. (3 Replies)
Discussion started by: sonujatav
3 Replies

2. Shell Programming and Scripting

How to capture the exit code of a shell script in a perl script.?

hi, i want to pop up an alert box using perl script. my requirement is. i am using a html page which calls a perl script. this perl script calls a shell script.. after the shell script ends its execution, i am using exit 0 to terminate the shell script successfully and exit 1 to terminate the... (3 Replies)
Discussion started by: Little
3 Replies

3. Shell Programming and Scripting

Exit a shell script

Hi Guys, How can I exit from the shell script if a condition is not met? Thanks in advance... (2 Replies)
Discussion started by: Phuti
2 Replies

4. Shell Programming and Scripting

exit shell from a script

hi guys I have a script that I need to terminate or exit the shell or session completely for the user but the exit only exit from the script and takes the user to the shell I found this https://www.unix.com/unix-dummies-questions-answers/399-using-exit-command-shell-script.html saying that... (1 Reply)
Discussion started by: kopper
1 Replies

5. Shell Programming and Scripting

How to grep sql error in shell script and exit the script?

I need help in the following script. I want to grep the sql errors insert into the error table and exit the shell script if there is any error, otherwise keep running the scripts. Here is my script #!/bin/csh -f source .orapass set user = $USER set pass = $PASS cd /opt/data/scripts echo... (2 Replies)
Discussion started by: allinshell99
2 Replies

6. Shell Programming and Scripting

Normal exit from shell script

How to do a normal exit from .SH program (1 Reply)
Discussion started by: 1manraj1
1 Replies

7. Shell Programming and Scripting

unable to exit from a shell script

Hi All, I am unable to exit from a shell script using the below code: #!/bin/ksh passchk() ( if ;then echo "Password validated" else echo "Wrong password Quiting the application..." exit 0#not working fi ) passchk (Note:"finalresult" passed to the passchk... (2 Replies)
Discussion started by: Sreejith_VK
2 Replies

8. Shell Programming and Scripting

exit a shell script!!

could somebody tell me please how to exit a shell script: if then echo "No arguments detected" exit 1 fi ... echo "still there" # is displayed .. :-( (4 Replies)
Discussion started by: sami98
4 Replies

9. Shell Programming and Scripting

exit shell script from function

Hi all, I have tried to put a exit 0 statement within a function I have created in the shell script but it doesn't seem to exit out of the script? Can someone tell me why? And is there any other way to exit out of the script from within a function? Thanks! (1 Reply)
Discussion started by: nvrh7
1 Replies

10. UNIX for Dummies Questions & Answers

using exit command in a shell script

Can it be done? If so, how? I would like a script to contain the exit command, and log me off at script completion. thanks (1 Reply)
Discussion started by: jpprial
1 Replies

Featured Tech Videos