LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-09-2010, 07:46 PM   #1
twrig3846
LQ Newbie
 
Registered: Jan 2010
Posts: 7

Rep: Reputation: 0
Cool shell script fails to exit


This is a very simple problem, but i'm scratching my head with others..

In composing a simple shell script in class, we can't seem to get the script to execute fully. script was formatted as follows.

#!/bin/bash
echo "good bye for now"
exit

did, Chmod 755 to make executable
type file name "bye"
runs but wont exit.....
it just echos the type"good bye for now
The instructor says it works for him at home....
But it wont work in class...
Is there a reason it wont "exit" the shell as commanded ?????

we are using putty with bash shell Linux.

Last edited by twrig3846; 02-09-2010 at 08:27 PM. Reason: wrong chmod code
 
Old 02-09-2010, 08:23 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
What do you mean by "doesn't exit"? You don't get to a shell prompt,
it just sits there as if in a loop??
 
Old 02-09-2010, 11:10 PM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Works for me.
Code:
c:~$ echo '#!/bin/bash
> echo "good bye for now"
> exit' > /tmp/bye.sh
c:~$ chmod +x /tmp/bye.sh
c:~$ /tmp/bye.sh
good bye for now
c:~$
What are you doing different?
 
Old 02-09-2010, 11:27 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Hmmm ... maybe he expects the 'exit' in the script
to do what it would do on the shell - terminate the
session, close his putty connection?
 
Old 02-09-2010, 11:32 PM   #5
twrig3846
LQ Newbie
 
Registered: Jan 2010
Posts: 7

Original Poster
Rep: Reputation: 0
wont exit

Yes it appears to echo good bye and returns to the shell prompt, the
instructor leads me to believe that this script should run and leave you
exiting the Linux program and exits back to windows, I seem to be missing
something somewhere...

When I type in the filename which is "bye" He says this should leave the Linux completely after saying "goodbye" or rather typing it.and cause you to exit as if you typed "exit" and hit enter.
 
Old 02-09-2010, 11:38 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Well ask him where he got that idea from.

An exit in a script will only terminate the SUB-shell that
you invoked when starting the script.
 
Old 02-09-2010, 11:51 PM   #7
twrig3846
LQ Newbie
 
Registered: Jan 2010
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by catkin View Post
Works for me.
Code:
c:~$ echo '#!/bin/bash
> echo "good bye for now"
> exit' > /tmp/bye.sh
c:~$ chmod +x /tmp/bye.sh
c:~$ /tmp/bye.sh
good bye for now
c:~$
What are you doing different?
I don't seem to be doing anything different, Maybe he is just testing us.
his statement was "does it work or not" if not why? and if so why?
maybe I'm chasing my tail, I know the exit command works if I'm not in the directory he tells us to be in so maybe that's my clue.
He starts us out by making a directory named bin in our home directory and in this directory to make a file named bye and to make this file executable and run this bye script.......this is where I'm at....????
 
Old 02-09-2010, 11:53 PM   #8
twrig3846
LQ Newbie
 
Registered: Jan 2010
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Tinkster View Post
Well ask him where he got that idea from.

An exit in a script will only terminate the SUB-shell that
you invoked when starting the script.
You know I was just discussing this with my wife and thought of the exact same thing....I think he is testing me..The Instructor that is..
 
Old 02-09-2010, 11:53 PM   #9
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726

Rep: Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706
Quote:
Originally Posted by twrig3846 View Post
I don't seem to be doing anything different, Maybe he is just testing us.
his statement was "does it work or not" if not why? and if so why?
There's your answer.

Evo2.
 
Old 02-09-2010, 11:59 PM   #10
twrig3846
LQ Newbie
 
Registered: Jan 2010
Posts: 7

Original Poster
Rep: Reputation: 0
I know I'm still a newbie and am learning all the time..Thanks to all who helped me out tonight, You have been a great help..I thought all along that this was the case but was expected to find my own answer.. The KW book and the SKS are very vague in some explanations...Thank You
 
Old 02-10-2010, 12:01 AM   #11
twrig3846
LQ Newbie
 
Registered: Jan 2010
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by evo2 View Post
There's your answer.

Evo2.
Thanks I thought so all along but wasn't sure...
 
Old 02-10-2010, 12:10 AM   #12
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,434

Rep: Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790
Here's some very good tutorials for bash etc
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

BTW if you 'sourced' the script, it would log you off ie

Code:
. script.sh

OR

source script.sh

Read those links to see why...
 
1 members found this post helpful.
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to exit out of the calling Shell Script harimac Linux - Newbie 3 08-19-2009 01:49 AM
How to properly exit functions in Shell Script? Jude Terror Programming 5 01-27-2009 03:15 PM
optional exit from loop, shell script RudraB Programming 2 07-17-2008 03:30 AM
what is the script which runs at the exit bash shell supersubu123 Linux - General 6 01-24-2007 12:25 PM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 02:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:21 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration