LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 09-02-2009, 06:50 PM   #1
bert07
Member
 
Registered: Jul 2007
Location: Belgium, Heist-op-den-Berg
Distribution: Ubuntu, Windows, Puppy, and about 50 others on or off
Posts: 63

Rep: Reputation: 16
How to exit BASH with a BASH script


I have a kind of stupid question and/or problem.

When I use the DOS terminal, I close the terminal window just by typing:
Code:
$ x
followed by a return.
This worked because I had a (very) small batch file called "x.bat":
Code:
@ECHO OFF
EXIT
Now I try to write a simular script "x" for BASH, but it does not seem to work:
Code:
#! /bin/bash
exit
The script is found, but it just does not do anything. (When I change the script to "echo exit", it echo's, so the PATH is okay.)

As you might have guessed: I am complete new in shell scripting.

Maybe I need a script that sends the CTRL-SHIFT-Q keys to BASH?

Can someone enlighten me?
 
Old 09-02-2009, 07:00 PM   #2
theNbomr
Senior Member
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 4,506

Rep: Reputation: 602Reputation: 602Reputation: 602Reputation: 602Reputation: 602Reputation: 602
Things that work in DOS batch scripts don't always work the same in bash. In this case, it fails because using a shell script causes a child shell process to be launched. When the child shell invokes 'exit', it simply exits itself, leaving the parent process intact.
To accomplish your objective, you could make an alias.
Code:
alias x='exit'
Or, you could use the existing 'Ctrl-D', that already serves your purpose as a side effect of its actual purpose.
--- rod.

Last edited by theNbomr; 09-03-2009 at 02:13 AM.
 
Old 09-02-2009, 07:26 PM   #3
bert07
Member
 
Registered: Jul 2007
Location: Belgium, Heist-op-den-Berg
Distribution: Ubuntu, Windows, Puppy, and about 50 others on or off
Posts: 63

Original Poster
Rep: Reputation: 16
CTRL-D does just fine.
Thanks. I didn't know that.

But pray tell me about the alias: how do I make it and in which file?
 
Old 09-02-2009, 08:12 PM   #4
bert07
Member
 
Registered: Jul 2007
Location: Belgium, Heist-op-den-Berg
Distribution: Ubuntu, Windows, Puppy, and about 50 others on or off
Posts: 63

Original Poster
Rep: Reputation: 16
Okay.
I found it:

/etc/bash.bashrc

Thanks again.
 
Old 09-03-2009, 02:19 AM   #5
theNbomr
Senior Member
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 4,506

Rep: Reputation: 602Reputation: 602Reputation: 602Reputation: 602Reputation: 602Reputation: 602
Like most bash configurations, you can simply type them at the commandline, and they will hold for the life of that shell, and generally any child shells will inherit the configuration. Using .bashrc in your $HOME directory will cause all new shells to inherit the changes. You can cause any existing shell instances to pick up your new settings by sourcing the bash startup script:
Code:
source ~/.bashrc
Finally, you can put the configuration changes in /etc/bashrc, and they will be available to all users.
--- rod
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Log what exits in bash script. What causes exit code thats not 0? Trailsmoke Programming 2 09-25-2008 03:07 AM
what is the script which runs at the exit bash shell supersubu123 Linux - General 6 01-24-2007 12:25 PM
Bash: Print usage statement & exit; otherwise continue using Bash shorthand operators stefanlasiewski Programming 9 02-07-2006 05:20 PM
Bash Script- command on exit PDock Programming 6 12-23-2005 07:03 PM


All times are GMT -5. The time now is 03:25 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration