Re: Bash script question (was: Re: Netscape 4.73 wrapper broken)

2000-06-25 Thread kmself
On Fri, Jun 23, 2000 at 08:51:44PM -0400, Peter Kovacs wrote:
 On Sat, 24 Jun 2000, Mark Phillips wrote:

  for f in $(cd
 
 From man 1 bash:
Command Substitution
Command substitution allows the output  of  a  command  to
replace the command name.  There are two forms:
 
   $(command)
or
   `command`
 
 That's why I had the backticks in there.  I've never seen the
 $() construct either.  

The key difference is that $( command list ) is nestable without
quoting, backticks are not.

If you've ever written:

   $ foo `bar \`baz qux\` ` 

...nested to several levels, you'll appreciate:

   $ foo $( bar $( baz qux ) )
   
...it becomes trivial to build complex expressions interatively on the
command line with command-line editing, without having to worry about
quoting backticks and such. 

The functionality is common in a number of shells other than bash,
though I'm not quite sure which.  I believe the Unix posix-compliant
(bastardized korn) and possibly korn shells support it.

-- 
Karsten M. Self kmself@ix.netcom.com http://www.netcom.com/~kmself
  Evangelist, Opensales, Inc.   http://www.opensales.org
   What part of Gestalt don't you understand?  Debian GNU/Linux rocks!
 http://gestalt-system.sourceforge.net/  K5: http://www.kuro5hin.org
GPG fingerprint: F932 8B25 5FDD 2528 D595  DC61 3847 889F 55F2 B9B0


pgpjLcEuXwtaX.pgp
Description: PGP signature


Re: Bash script question (was: Re: Netscape 4.73 wrapper broken)

2000-06-25 Thread Colin Watson
kmself@ix.netcom.com wrote:
The key difference is that $( command list ) is nestable without
quoting, backticks are not.

[snip]

The functionality is common in a number of shells other than bash,
though I'm not quite sure which.  I believe the Unix posix-compliant
(bastardized korn) and possibly korn shells support it.

Looking through the shells I have installed, ash and zsh support it too.
As I remember, it only appeared in bash as of version 2.

-- 
Colin Watson [EMAIL PROTECTED]



Re: Bash script question (was: Re: Netscape 4.73 wrapper broken)

2000-06-24 Thread Andre Berger
Peter Kovacs [EMAIL PROTECTED] writes:

 On Sat, 24 Jun 2000, Mark Phillips wrote:
 From man 1 bash:
Command Substitution
Command substitution allows the output  of  a  command  to
replace the command name.  There are two forms:
 
   $(command)
or
   `command`
 
 That's why I had the backticks in there.  I've never seen the
 $() construct either.  

You can use it for

kill -9 $(pidof netscape)

to get rid of all processes that have the string netscape in their
names ;)

Andre



Re: Bash script question (was: Re: Netscape 4.73 wrapper broken)

2000-06-24 Thread Marek Habersack
** On Jun 24, Mark Phillips scribbled:
 Corey Popelier [EMAIL PROTECTED] wrote:
 
  Yes I have this problem also. I assume we shall await a fix. And use
  Mozilla in the meantime :)
[snip]
 And the problem seems to be with a syntax error at the line
 
 for f in (cd $d;ls -1 . | sort); do
 
 According to man bash, the (cd $d;ls -1 . | sort) is a compound
You shouldn't rely on what bash supports or not. The Debian shell scripts
are supposed to be POSIX-compatible, and not everything bash implements is
POSIX.

 command where the stuff in brackets is executed in its own shell.  So
 what this line seems to be trying to do, is to go to a certain
 directory, get a sorted listing of the files there and then go through
 them one by one, executing . $d/$f for each of them.  What is the
 . command???  I thought it was the current directory?
It's the 'source' command. It takes its argument and interprets the file as
a shell code - you might think of it as sort of dynamic linking for scripts.

 Anyway, the reason for the syntax error is with the definition of a
 for loop in bash.  From man bash:
 
   for name [ in word ] ; do list ; done
Again, don't rely on bash being the /bin/sh. Debian scripts cannot do that.

 Now word is a list of blank separated words I believe, so it does
 not allow the (cd $d;ls -1 . | sort) construction to be used here.
 So somehow we need to find an alternative.
I don't use that script, but I think adding $ before the first bracket would
do the trick.

 Any ideas?
Upgrade :)) - it will have been fixed when you read those words most
probably :))

marek


pgp8wKXz6IzN9.pgp
Description: PGP signature


Re: Bash script question (was: Re: Netscape 4.73 wrapper broken)

2000-06-24 Thread Marek Habersack
** On Jun 24, Mark Phillips scribbled:
 Peter Kovacs [EMAIL PROTECTED] wrote:
  On Fri, 23 Jun 2000, Peter Kovacs wrote:
  
   I'm sure that a fix has already been posted, but this works for me
   (replace the code above with this):
   
   for d in /usr/lib/netscape/base-4/wrapper.d ; do
   cd $d;
   for f in `find -maxdepth 1 -type f`; do
   . $d/$f  
   done
   done
  
  Wow.  I just realized how incredibly incorrect the code is.  Well, it
  works for me.  YMMV though.  I'd wait for an official fix, or fix it
  yourself if the above doesn't work.
 
 What does YMMV stand for?
Your Mileage May Vary

   for f in $(cd
 
 It seems to work sort of, but I don't understand why!
The $(...) construct is a replacement for the old `...` construct which
means execute the comands between the single quotes (or the $(...)
sequence) and replace the expression with the output of the command
sequence. The command sequence is executed by a subshell, that is no side
effects occur to the current shell (pwd, environment etc.)
 
 And what is the . $d/$f supposed to do??
Read my previous posting.

marek


pgpfE5R1srHJ7.pgp
Description: PGP signature


Re: Bash script question (was: Re: Netscape 4.73 wrapper broken)

2000-06-24 Thread Andre Berger
Andre Berger [EMAIL PROTECTED] writes:

Sorry, use

  kill -9 $(pidof communicator-smotif.real)

or something like that.

Andre

 Peter Kovacs [EMAIL PROTECTED] writes:
 
  On Sat, 24 Jun 2000, Mark Phillips wrote:
  From man 1 bash:
 Command Substitution
 Command substitution allows the output  of  a  command  to
 replace the command name.  There are two forms:
  
$(command)
 or
`command`
  
  That's why I had the backticks in there.  I've never seen the
  $() construct either.  
 
 You can use it for
 
   kill -9 $(pidof netscape)
 
 to get rid of all processes that have the string netscape in their
 names ;)
 
 Andre



Bash script question (was: Re: Netscape 4.73 wrapper broken)

2000-06-23 Thread Mark Phillips
Corey Popelier [EMAIL PROTECTED] wrote:

 Yes I have this problem also. I assume we shall await a fix. And use
 Mozilla in the meantime :)

Or we could try to fix it... the error is with the code:

for d in \
/usr/lib/netscape/base-4/wrapper.d \
/usr/lib/netscape/$VER \
/usr/lib/netscape/$VER/$BIN ;do
for f in (cd $d;ls -1 . | sort); do
. $d/$f
done
done

And the problem seems to be with a syntax error at the line

for f in (cd $d;ls -1 . | sort); do

According to man bash, the (cd $d;ls -1 . | sort) is a compound
command where the stuff in brackets is executed in its own shell.  So
what this line seems to be trying to do, is to go to a certain
directory, get a sorted listing of the files there and then go through
them one by one, executing . $d/$f for each of them.  What is the
. command???  I thought it was the current directory?

Anyway, the reason for the syntax error is with the definition of a
for loop in bash.  From man bash:

  for name [ in word ] ; do list ; done

Now word is a list of blank separated words I believe, so it does
not allow the (cd $d;ls -1 . | sort) construction to be used here.
So somehow we need to find an alternative.

Any ideas?

Thanks,

Mark.

P.S. For any replies, please cc a copy directly to me.


 On Fri, 23 Jun 2000, Mark Phillips wrote:
 
  I've just updated my system to the current frozen, and included in
  this update was the installation of netscape 4.73.
  
  When I now run netscape, it bombs out, complaining of:
  
  $ netscape
  /usr/bin/X11/netscape: line 277: syntax error near unexpected token `(c'
  /usr/bin/X11/netscape: line 277: `  for f in (cd $d;ls -1 . | 
  sort); do'
  
  Has anyone else had this problem?  Does anyone else know the fix?
  
  Thanks,
  
  Mark.
  
  P.S. Please cc a copy of any reply directly to me as I currently read
  the list only via the archives --- and I can't even do that now that
  netscape is not working.
  
  -- 
  _/\___/~~\
  /~~\_/~~\__/~~\__Mark_Phillips
  /~~\_/[EMAIL PROTECTED]
  /~~\HE___/~~\__/~~\APTAIN_
  /~~\__/~~\
  __
  They told me I was gullible ... and I believed them! 
  
  
  -- 
  Unsubscribe?  mail -s unsubscribe [EMAIL PROTECTED]  /dev/null
  
 

-- 
_/\___/~~\
/~~\_/~~\__/~~\__Mark_Phillips
/~~\_/[EMAIL PROTECTED]
/~~\HE___/~~\__/~~\APTAIN_
/~~\__/~~\
__
They told me I was gullible ... and I believed them! 



Re: Bash script question (was: Re: Netscape 4.73 wrapper broken)

2000-06-23 Thread Peter Kovacs
On Sat, 24 Jun 2000, Mark Phillips wrote:

 for d in \
 /usr/lib/netscape/base-4/wrapper.d \
 /usr/lib/netscape/$VER \
 /usr/lib/netscape/$VER/$BIN ;do
 for f in (cd $d;ls -1 . | sort); do
 . $d/$f
 done
 done

I'm sure that a fix has already been posted, but this works for me
(replace the code above with this):

for d in /usr/lib/netscape/base-4/wrapper.d ; do
cd $d;
for f in `find -maxdepth 1 -type f`; do
. $d/$f  
done
done

Peter

--
Peter D. Kovacs   KnowPost.com LLC
Lead Engineer   [EMAIL PROTECTED]
--



Re: Bash script question (was: Re: Netscape 4.73 wrapper broken)

2000-06-23 Thread Mark Phillips
Peter Kovacs [EMAIL PROTECTED] wrote:
 On Fri, 23 Jun 2000, Peter Kovacs wrote:
 
  I'm sure that a fix has already been posted, but this works for me
  (replace the code above with this):
  
  for d in /usr/lib/netscape/base-4/wrapper.d ; do
  cd $d;
  for f in `find -maxdepth 1 -type f`; do
  . $d/$f  
  done
  done
 
 Wow.  I just realized how incredibly incorrect the code is.  Well, it
 works for me.  YMMV though.  I'd wait for an official fix, or fix it
 yourself if the above doesn't work.

What does YMMV stand for?

An official fix has come through, and what it does is replace

for f in (cd.

by

for f in $(cd

It seems to work sort of, but I don't understand why!

And what is the . $d/$f supposed to do??

Cheers,

Mark.

-- 
_/\___/~~\
/~~\_/~~\__/~~\__Mark_Phillips
/~~\_/[EMAIL PROTECTED]
/~~\HE___/~~\__/~~\APTAIN_
/~~\__/~~\
__
They told me I was gullible ... and I believed them! 



Re: Bash script question (was: Re: Netscape 4.73 wrapper broken)

2000-06-23 Thread Peter Kovacs
On Sat, 24 Jun 2000, Mark Phillips wrote:

 What does YMMV stand for?

YMMV = Your Mileage May Vary

 An official fix has come through, and what it does is replace
 
   for f in (cd.
 
 by
 
   for f in $(cd

From man 1 bash:
   Command Substitution
   Command substitution allows the output  of  a  command  to
   replace the command name.  There are two forms:

  $(command)
   or
  `command`

That's why I had the backticks in there.  I've never seen the
$() construct either.  

 And what is the . $d/$f supposed to do??
 

Again, from man 1 bash:
.  filename [arguments]
   source filename [arguments]
  Read and execute commands from filename in the curĀ­
  rent  shell  environment and return the exit status
  of the last command  executed  from  filename...

It simply executes those files as a shell script.

Peter

--
Peter D. Kovacs   KnowPost.com LLC
Lead Engineer   [EMAIL PROTECTED]
--




Re: Bash script question (was: Re: Netscape 4.73 wrapper broken)

2000-06-23 Thread John Pearson
On Fri, Jun 23, 2000 at 08:51:44PM -0400, Peter Kovacs wrote
 On Sat, 24 Jun 2000, Mark Phillips wrote:
 
  What does YMMV stand for?
 
 YMMV = Your Mileage May Vary
 
  An official fix has come through, and what it does is replace
  
  for f in (cd.
  
  by
  
  for f in $(cd
 
 From man 1 bash:
Command Substitution
Command substitution allows the output  of  a  command  to
replace the command name.  There are two forms:
 
   $(command)
or
   `command`
 
 That's why I had the backticks in there.  I've never seen the
 $() construct either.  
 
  And what is the . $d/$f supposed to do??
  
 
 Again, from man 1 bash:
 .  filename [arguments]
source filename [arguments]
   Read and execute commands from filename in the curĀ­
   rent  shell  environment and return the exit status
   of the last command  executed  from  filename...
 
 It simply executes those files as a shell script.
 

To be more accurate, it executes the contents of those files
as if they had been included in the current script.  No new 
shell, all the current parameters accessible, any parameters
or functions defined in those files available in the current
context.


John P.
-- 
[EMAIL PROTECTED]
[EMAIL PROTECTED]
http://www.mdt.net.au/~john Debian Linux admin  support:technical services