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, 08: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 09:27 PM. Reason: wrong chmod code
 
Old 02-09-2010, 09:23 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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-10-2010, 12:10 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
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-10-2010, 12:27 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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-10-2010, 12:32 AM   #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-10-2010, 12:38 AM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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-10-2010, 12:51 AM   #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-10-2010, 12:53 AM   #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-10-2010, 12:53 AM   #9
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
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-10-2010, 12:59 AM   #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, 01: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, 01:10 AM   #12
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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 02:49 AM
How to properly exit functions in Shell Script? Jude Terror Programming 5 01-27-2009 04:15 PM
optional exit from loop, shell script RudraB Programming 2 07-17-2008 04:30 AM
what is the script which runs at the exit bash shell supersubu123 Linux - General 6 01-24-2007 01:25 PM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 03:34 PM


All times are GMT -5. The time now is 08:32 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration