The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Bash shell script outthere_3 UNIX for Dummies Questions & Answers 2 01-31-2008 08:13 PM
BASH Shell Script Help -HELP! flamethrower0 Shell Programming and Scripting 2 12-30-2006 01:26 AM
bash shell script and ms-dos space13 Shell Programming and Scripting 1 11-10-2006 07:06 PM
need help with bash shell script vmtailor UNIX for Dummies Questions & Answers 2 03-03-2005 04:30 PM
bash shell script norsk hedensk Shell Programming and Scripting 4 08-02-2003 07:27 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-28-2008
saurabh84g saurabh84g is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 55
Question Bash Shell to sh Shell In a Script

Hi All,
I am in Bash Shell and Running A script that contains Exit statement in that in last ( to return to sh shell after executing) But it is not coming to sh shell after the script is excuted.
How to return to sh shell from bash shell through a script.
  #2 (permalink)  
Old 08-28-2008
FractalizeR FractalizeR is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 24
If it doesn't return, what happens then? It just hangs up opr what? May be in the last lines of script some lengthy command is executing?
  #3 (permalink)  
Old 08-28-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Post your script within code tags (select the code and click on the '#' above the edit window), and we'll see how we can assist.

Regards
  #4 (permalink)  
Old 08-28-2008
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 560
Quote:
Originally Posted by saurabh84g View Post
Hi All,
I am in Bash Shell and Running A script that contains Exit statement in that in last ( to return to sh shell after executing) But it is not coming to sh shell after the script is excuted.
How to return to sh shell from bash shell through a script.
Please post your code or use "sh -x scriptname " to see its execution to find out where it gets hang
  #5 (permalink)  
Old 08-28-2008
saurabh84g saurabh84g is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 55
Question Reply to Above Thread

Actually i m just redirecting the output of single command to a file name ( for the Database)

through a script

ping localhost > abc.sh$"$(date ' +%d%b%y')".lst
exit

Case1)
Bash-3.2#./abc.sh
Bash-3.2#

output)abc28Aug.lst == correct output===

Case2) #./abc.sh

output) abc$$(date '+%d%b%y').lst ===wrong output=====

After executing in a bash shell it should not come to bash shell ,
i want to run the script from the sh shell only ?
  #6 (permalink)  
Old 08-29-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Quote:
Originally Posted by saurabh84g View Post
Case1)
Bash-3.2#./abc.sh
Bash-3.2#

output)abc28Aug.lst == correct output===
When you run any shell script it spawns a new shell, so including an exit statement will have no effect, you will still be returned to the parent shell that you run it from (unless you "source" the script using . ./abc.sh).

Quote:
Originally Posted by saurabh84g View Post
Case2) #./abc.sh

output) abc$$(date '+%d%b%y').lst ===wrong output=====
If you need to run the shell from sh, but have it interpreted by bash, then just add a shebang line as the first line of the script, e.g.

Code:
#!/usr/bin/bash
ping localhost > abc.sh$"$(date ' +%d%b%y')".lst
Also, I'm nost sure why you have the extra $"" around the date command, this should be enough:

Code:
#!/usr/bin/bash
ping localhost > abc.sh$(date '+%d%b%y').lst
  #7 (permalink)  
Old 08-28-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Probably you end up running a different version of ping which just keeps on looping forever. Perhaps your PATH is different in Bash than in the regular Bourne shell. Try specifying an explicit pathname like /bin/ping or whatever works for you.

Some versions of ping accept an argument -c 1 which says to send only one packet and then quit (or any number after -c of course); if not specified, they will loop forever.

If your shell doesn't understand $(...) you can use `...` instead (those are grave accents -- ASCII 96 -- not regular straight apostrophes).
Closed Thread

Bookmarks

Tags
bash, shell

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0