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
Invoking Oracle stored procedure in unix shell script hidnana Shell Programming and Scripting 1 10-15-2008 07:37 AM
returning to the parent shell after invoking a script within a script gurukottur Shell Programming and Scripting 5 09-26-2006 07:05 AM
Invoking Shell Script via php bubeshj Shell Programming and Scripting 2 06-30-2006 06:09 AM
Invoking shell script from html/jsp page bubeshj Shell Programming and Scripting 2 06-28-2006 01:53 PM
invoking one shell script from other ajay xavier Shell Programming and Scripting 3 05-24-2006 03:39 AM

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 09-10-2003
kowrip kowrip is offline
Registered User
  
 

Join Date: Sep 2003
Location: New Jersey
Posts: 32
Wrong Shell Invoking My Script On Linux

I have a shell script that does NOT have the '#!' line at the top. It is written for ksh. The shell in my passwd entry is '/usr/bin/ksh' and my SHELL env variable is '/usr/bin/ksh'. Now, here's the issue. I invoke the script on Solaris with './myprog'. This works fine. I also run the same script on Mandrake 9.0 Linux and Red Hat 7.3 Linux. It runs fine on both of these. Again, my SHELL env variable and passwd entry both have '/usr/bin/ksh'. When I invoke the program on Red Hat 7.2 with './myprog', it is using the '/bin/sh' shell. Why would this be ? If my SHELL var and passwd entry both point to 'ksh', I don't understand how it would be using '/bin/sh'. Also, I can't just add the '#!' line to the top because this script invokes other scripts as well and it just pushes the problem to a different point. Any ideas ????
  #2 (permalink)  
Old 09-10-2003
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Re: Wrong Shell Invoking My Script On Linux

Quote:
Originally posted by kowrip
I have a shell script that does NOT have the '#!' line at the top.
Then it is broken.
Quote:
Originally posted by kowrip

Also, I can't just add the '#!' line to the top because this script invokes other scripts as well and it just pushes the problem to a different point. Any ideas ????
You have a finite number of scripts. And the #! line to each one.

As for what is happening, see this thread.
  #3 (permalink)  
Old 09-10-2003
kowrip kowrip is offline
Registered User
  
 

Join Date: Sep 2003
Location: New Jersey
Posts: 32
Re: Re: Wrong Shell Invoking My Script On Linux

Quote:
Originally posted by Perderabo
Then it is broken.

You have a finite number of scripts. And the #! line to each one.

As for what is happening, see this thread.
Thanks. This behavior was quite surprising to me and my co-workers. We always thought that the system will use whatever your current $SHELL is to run scripts without the "#!". This script is a setup script for a bigger program and it was always without the "#!". I guess I'll add it to the top of the file now that I know.
  #4 (permalink)  
Old 09-10-2003
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
The second shell for unix was csh. Shortly after csh arrived, the SHELL environment variable was introduced. It was set to the value of the shell field in /etc/passwd. From it's inception, it was intended to be the user's favorite interactive shell. Programs like vi refer to it when when they are asked to spawn an interactive shell. If it also was for scripts, that would mean that we must use the same shell for interactive use and for scripts. csh was better than sh as an interactive shell but sh was better than csh for scripts.

The only exception to this that I know of is with the program "make". It reads the environment and treats each environment variable as a make macro. That includes the SHELL macro, the environment SHELL variable overrides make's internal deafault for SHELL. So all non-trivial makefiles now explicitly set the SHELL macro. make's habit of assuming that the entire environment is intended for it is not great behavior.
Closed Thread

Bookmarks

Tags
shell environment variable, shell scripting

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 03:41 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