LinuxQuestions.org
Visit Jeremy's Blog.
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 11-23-2009, 02:11 PM   #1
lk4772
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Rep: Reputation: 0
script closing window


Hello! I'm new to this site, and trying to refresh my memory from 5 years ago since I last worked with Oracle and Unix. So please be patient with me! LOL

I have a shell script using sh that whenever I run it, it closes my Putty session! The script has only 2 lines, an echo statement and the first is the #!/bin/sh command....any help would be much appreciated! thanks!
 
Old 11-23-2009, 02:12 PM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Can you show a copy of the script?
 
Old 11-23-2009, 02:14 PM   #3
lk4772
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Original Poster
Rep: Reputation: 0
script

I had even commented out the echo statement and it still closes the window? here's the exact contents of the script - I wrote using the VI editor so that there shouldn't be any problems with return characters...


#!/bin/sh
#echo "starting script";
 
Old 11-23-2009, 02:29 PM   #4
lk4772
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Original Poster
Rep: Reputation: 0
also tried

I also tried using the printf function instead of echo, but that closes my putty session as well....
 
Old 11-23-2009, 03:16 PM   #5
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
*How* are you running this script? Step by step, please.

That script does actually nothing because everything is commented out. At most, it should echo a message if you uncoment the 2nd line.
 
Old 11-23-2009, 03:27 PM   #6
lk4772
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Original Poster
Rep: Reputation: 0
running script

I'm logging into putty, using the "cd" command I'm going to the directory where the script is stored, and then I'm typing in "exec <scriptname>"

I know the script isn't really doing anything, I'm just trying to get started on verifying that an easy script (like this one) will work so that I can figure out why another script is not working by adding in pieces/parts of the other script, but I don't want it to close putty all the time - don't want to keep logging back in - does that make sense?
 
Old 11-23-2009, 03:33 PM   #7
lk4772
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Original Poster
Rep: Reputation: 0
another try

I have also just tried the below script, and it worked - displayed the #1, but as soon as I put the last line in ("echo script started;") it closes the window - tried it with and without the quotes around script started....

#!/bin/sh
export LeisaNbr=0;
let "LeisaNbr = LeisaNbr + 1";
echo $LeisaNbr;
echo script started;
 
Old 11-23-2009, 03:37 PM   #8
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by lk4772 View Post
I'm logging into putty, using the "cd" command I'm going to the directory where the script is stored, and then I'm typing in "exec <scriptname>"
That's what I wanted to hear. "exec" forks a new process, then terminates the current shell. When the script ends, there's nothing in putty, no shell, so it closes.

Quote:
I know the script isn't really doing anything, I'm just trying to get started on verifying that an easy script (like this one) will work so that I can figure out why another script is not working by adding in pieces/parts of the other script, but I don't want it to close putty all the time - don't want to keep logging back in - does that make sense?
It's not the script, simply don't use exec. Either use:

Code:
sh <scriptname>
or chmod it conveniently and run it this way:

Code:
chmod a+x <scriptname>
./<scriptname>
You only have to chmod it once, of course. After that, you can run it that way.
 
Old 11-23-2009, 03:39 PM   #9
lk4772
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Thank you!!!

that worked!!
 
  


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
Closing a window kanik Programming 1 09-30-2008 03:28 AM
My bash window keeps closing... otacon 14112 Linux - Security 12 04-05-2007 09:28 PM
Javasript - closing a window djgerbavore Programming 1 05-06-2005 01:01 PM
closing a frozen window!? ungua Linux - Software 6 11-14-2004 01:38 PM
Close window error when not closing firehawk573 Programming 0 03-22-2004 03:05 PM

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

All times are GMT -5. The time now is 06:49 AM.

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