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
Small Search script appu1987 Shell Programming and Scripting 2 06-03-2008 10:14 PM
small script help ali560045 Shell Programming and Scripting 9 01-18-2008 10:18 AM
Very small Shell Script Help... marconi Shell Programming and Scripting 2 12-11-2007 05:44 AM
small script everurs789 Shell Programming and Scripting 3 11-06-2007 05:08 PM
Need help in a small script super_duper_guy Shell Programming and Scripting 2 10-24-2005 10:06 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 12-06-2005
rkl1 rkl1 is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 6
small script help

here is a small script:

if [ $# -lt 1 ]; then
echo please enter an argument
fi
if [ "$1" = "tom"; then
a=$1
echo $a
fi

here is my question. if the script name is j.sh and I run it : j.sh from shell prompt: without a parameter: it prints please enter an argument but if I go with . j.sh (current shell execution): it does not show that.

also if I go with an argument $ j.sh tom or $ . j.sh tom
the result is identical. however the next time I go with no argument, still I see the variable has a value tom with $ . j.sh tom. what makes the current shell execution keep the variable to value assigned even if on the next trun no argument is passed.

any suggestion would be highly appreciated.

thanks.
  #2 (permalink)  
Old 12-06-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
When you run a script like ./test.sh, then you fork a subshell and all execution is carried out in the context of that shell. Any environment variables that are set are done so in the env of the subshell. The environment of the current shell is not modified.
However, when you run a script like . ./test.sh, then you are changing the environment of the current shell and setting the various values as per your script. After the script is done, the values remain set as you are still running in the shell where the environment was modified.

Hope this is clear.
Closed Thread

Bookmarks

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 06:49 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