delorie.com/archives/browse.cgi | search |
X-Authentication-Warning: | delorie.com: mailnull set sender to djgpp-workers-bounces using -f |
Subject: | Re: Some small bash issues |
From: | Tim Van Holder <tim DOT van DOT holder AT pandora DOT be> |
To: | Eli Zaretskii <eliz AT is DOT elta DOT co DOT il> |
Cc: | djgpp-workers AT delorie DOT com |
In-Reply-To: | <Pine.SUN.3.91.1020214121957.28394L-100000@is> |
References: | <Pine DOT SUN DOT 3 DOT 91 DOT 1020214121957 DOT 28394L-100000 AT is> |
X-Mailer: | Evolution/1.0.2 |
Date: | 14 Feb 2002 13:42:49 +0100 |
Message-Id: | <1013690570.30677.90.camel@bender.falconsoft.be> |
Mime-Version: | 1.0 |
Reply-To: | djgpp-workers AT delorie DOT com |
Errors-To: | nobody AT delorie DOT com |
X-Mailing-List: | djgpp-workers AT delorie DOT com |
X-Unsubscribes-To: | listserv AT delorie DOT com |
On Thu, 2002-02-14 at 11:21, Eli Zaretskii wrote: > > On 14 Feb 2002, Tim Van Holder wrote: > > > foo=bar ./shell-script > > > > because everything in the script is simply a 'new command'. > > I fail to see the difference between > > foo=bar ./script > and > foo=bar echo $foo > > What is the difference here? I thought that bash would see foo=bar ./script as foo=bar #!/bin/sh; first line; second line; ... I tried this on a Linux box, using bash 2.03 (bog standard bash for RH6.2). [tim AT bender] /home/tim>unset foo [tim AT bender] /home/tim>foo=bar echo $foo [tim AT bender] /home/tim>foo=bar echo $foo [tim AT bender] /home/tim>echo $foo * Note that this behaviour differs from ksh, where foo is defined after the first run (so the second and third echo both produce 'bar'). Not sure if this is a bug in either ksh or bash. Now for the interesting part: [tim AT bender] /home/tim>cat >fooscript <<\EOF More>echo $foo More>EOF [tim AT bender] /home/tim>chmod +x fooscript [tim AT bender] /home/tim>unset foo [tim AT bender] /home/tim>foo=bar ./fooscript bar [tim AT bender] /home/tim>cat >fooscript <<\EOF More>#! /bin/sh More>echo $foo More>EOF [tim AT bender] /home/tim>foo=bar ./fooscript bar [tim AT bender] /home/tim>echo $foo [tim AT bender] /home/tim>cat >fooscript <<\EOF More>#! /usr/bin/perl5 More>print $ENV{"foo"} . "\n"; More>EOF [tim AT bender] /home/tim>foo=bar ./fooscript bar [tim AT bender] /home/tim>foo=bar perl -e 'print $ENV{"foo"} . "\n";' bar [tim AT bender] /home/tim>echo $foo [tim AT bender] /home/tim>foo=bar perl -e 'print $ENV{"foo"} . "\n";' bar So running perl DOES set foo; running echo doesn't.
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |