RE: Cool shell tricks (was: Re: file system questions)

2000-10-22 Thread Avishay Aton


Hi, try this site for lots of tips an tricks


http://www.linux.com/tuneup



[Avishay Aton]  
 -Original Message-
 From: Shaul Karl [SMTP:[EMAIL PROTECTED]]
 Sent: Sunday, October 22, 2000 1:36 AM
 To:   [EMAIL PROTECTED]
 Subject:  Re: Cool shell tricks (was: Re: file system questions)
 
  On Sat, Oct 21, 2000 at 08:23:44AM +0200, Shaul Karl wrote:
Also, seems that not many people are aware of "process substitution"
in bash: you do something like "diff (ls dir1) (ls dir2)", and
 bash
runs two ls's, each writing to a FIFO, and diff gets the names of
these two FIFOs as parameters. Output redirection also works. I'm
 not
sure how portable it is, though.
   
 1.
   [08:05:37 /tmp]$ diff  (ls ~/setiathome/) (ls ~/setiathome/amos/)
   bash: syntax error near unexpected token `(l'
   [08:06:04 /tmp]$ 
   
   Ache, the space there is significant:
   
   [08:17:12 /tmp]$ diff (ls ~/setiathome/) (ls ~/setiathome/amos/)
  
  Yeah... Otherwise it's redirection.
  
 
 
 
 
 I am confused. Without the space it is not a redirection? Is there a 
 difference between a FIFO and a redirection?
 
 
 
  
 2.
   This will only work if the "main" process (diff in this example) does
 not need 
   to seek the input since it can not do it with a FIFO. Or am I missing 
   something?
  
  True... You can't. It would've been nice if Bash had the option to use
  temporary files rather than FIFOs... But I don't know if it's needed
  that often.
  
  Just tried: both nvi and vim cope fine, Emacs refuses to read it (at
  least with default setup and switches). Less requires you to use -f. 
  
  
  - Adi Stav
  
  =
  To unsubscribe, send mail to [EMAIL PROTECTED] with
  the word "unsubscribe" in the message body, e.g., run the command
  echo unsubscribe | mail [EMAIL PROTECTED]
  
 
 -- 
   
   Shaul Karl [EMAIL PROTECTED]
 
 
 
 =
 To unsubscribe, send mail to [EMAIL PROTECTED] with
 the word "unsubscribe" in the message body, e.g., run the command
 echo unsubscribe | mail [EMAIL PROTECTED]

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]




Re: Cool shell tricks (was: Re: file system questions)

2000-10-21 Thread Shaul Karl

 On Tue, Oct 17, 2000 at 04:59:48PM +0200, guy keren wrote:
  there is a dirty method you could use. every once in a while (perhaps even
  via a cron job), execute the command:
  
  :/path/to/.xsession-error
 
 Cool.
 
 I love these little shell tricks... I'm personally particularly fond
 of the old "(cd dir1; tar c) | (cd dir2; tar xv)" thing, but it's been
 discussed here extensively before.
 
 Also, seems that not many people are aware of "process substitution"
 in bash: you do something like "diff (ls dir1) (ls dir2)", and bash
 runs two ls's, each writing to a FIFO, and diff gets the names of
 these two FIFOs as parameters. Output redirection also works. I'm not
 sure how portable it is, though.
 


1.
[08:05:37 /tmp]$ diff  (ls ~/setiathome/) (ls ~/setiathome/amos/)
bash: syntax error near unexpected token `(l'
[08:06:04 /tmp]$ 

Ache, the space there is significant:

[08:17:12 /tmp]$ diff (ls ~/setiathome/) (ls ~/setiathome/amos/)
1,4c1
 NOTE
 README
 README.xsetiathome
 amos
---
 Release_Notes.txt
8a6
 result.sah
11c9
 setiathome-3.0.i386-pc-linux-gnu-gnulibc2.1.tar
---
 setiathome_win_3_0.exe
14a13
 windows_help.txt
16c15
 xsetiathome
---
 wtemp.sah
[08:18:20 /tmp]$ 

2.
This will only work if the "main" process (diff in this example) does not need 
to seek the input since it can not do it with a FIFO. Or am I missing 
something?


 Does anyone else like these tricks? I'd love to hear about other
 people's.
 
 
   - Adi Stav
 
 =
 To unsubscribe, send mail to [EMAIL PROTECTED] with
 the word "unsubscribe" in the message body, e.g., run the command
 echo unsubscribe | mail [EMAIL PROTECTED]
 

-- 

Shaul Karl [EMAIL PROTECTED]



=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]




Re: Cool shell tricks (was: Re: file system questions)

2000-10-21 Thread Nadav Har'El

On Fri, Oct 20, 2000, Adi Stav wrote about "Cool shell tricks (was: Re: file system 
questions)":
 On Tue, Oct 17, 2000 at 04:59:48PM +0200, guy keren wrote:
  there is a dirty method you could use. every once in a while (perhaps even
  via a cron job), execute the command:
  
  :/path/to/.xsession-error
 
 Cool.
 
 I love these little shell tricks... I'm personally particularly fond
..
 Does anyone else like these tricks? I'd love to hear about other
 people's.

When you know all the features of your shell (e.g., bash or zsh), it gives
you incredible power - both for interactive use and for programming (zsh
is a very capable programming language!).
To wield this power wisely, you'll need to know what exactly is available
to you, i.e., you should read the manual and/or texinfo documentation, and
see what cool features your shell has :)

6 years ago I switched from using ATT's (David Korn's) ksh to using zsh
because of a few features I was missing (such as smart completion). The Zsh
executable was then much bigger than ksh (now on Solaris it is about 2.5
bigger) and at first I thought that it was bloatware, adding, besides the
2-3 features I wanted, 20-30 extra useless features. Since then I changed
my mind - I've probably used each and every feature in zsh for something,
and I can't believe I once settled for ksh :)

-- 
Nadav Har'El|Saturday, Oct 21 2000, 22 Tishri 5761
[EMAIL PROTECTED] |-
Phone: +972-53-245868, ICQ 13349191 |How much wood would a woodchuck chuck if
http://nadav.harel.org.il   |a woodchuck would chuck wood?

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]




Re: Cool shell tricks (was: Re: file system questions)

2000-10-21 Thread Adi Stav

On Sat, Oct 21, 2000 at 08:23:44AM +0200, Shaul Karl wrote:
  Also, seems that not many people are aware of "process substitution"
  in bash: you do something like "diff (ls dir1) (ls dir2)", and bash
  runs two ls's, each writing to a FIFO, and diff gets the names of
  these two FIFOs as parameters. Output redirection also works. I'm not
  sure how portable it is, though.
 
   1.
 [08:05:37 /tmp]$ diff  (ls ~/setiathome/) (ls ~/setiathome/amos/)
 bash: syntax error near unexpected token `(l'
 [08:06:04 /tmp]$ 
 
 Ache, the space there is significant:
 
 [08:17:12 /tmp]$ diff (ls ~/setiathome/) (ls ~/setiathome/amos/)

Yeah... Otherwise it's redirection.


   2.
 This will only work if the "main" process (diff in this example) does not need 
 to seek the input since it can not do it with a FIFO. Or am I missing 
 something?

True... You can't. It would've been nice if Bash had the option to use
temporary files rather than FIFOs... But I don't know if it's needed
that often.

Just tried: both nvi and vim cope fine, Emacs refuses to read it (at
least with default setup and switches). Less requires you to use -f. 


- Adi Stav

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]




Re: Cool shell tricks (was: Re: file system questions)

2000-10-21 Thread Nadav Har'El

On Sat, Oct 21, 2000, Adi Stav wrote about "Re: Cool shell tricks (was: Re: file 
system questions)":
 True... You can't. It would've been nice if Bash had the option to use
 temporary files rather than FIFOs... But I don't know if it's needed
 that often.

Zsh has an additional process substition that looks like =(...), for example
xdvi =(zcat file.dvi.gz)

That creates a temporary file (a regular file, not a pipe) with the output
of the command, and passes that name to another command. I use it very
often - usually in the form of the example above.
I almost never use the (...) form: while it can be more efficiant, the
difference is barely noticable (on a modern computer) and many programs
(including xdvi) can't handle pipes as input files because they want to be
able to seek (rewind) into the file - so using temporary files instead of
a the pipe is like a "better safe than sorry".

I don't know if bash also has this form - check out its manual.

-- 
Nadav Har'El|Saturday, Oct 21 2000, 22 Tishri 5761
[EMAIL PROTECTED] |-
Phone: +972-53-245868, ICQ 13349191 |If God is watching us, the least we can
http://nadav.harel.org.il   |do is be entertaining.

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]




Re: Cool shell tricks (was: Re: file system questions)

2000-10-21 Thread Shaul Karl

 On Sat, Oct 21, 2000 at 08:23:44AM +0200, Shaul Karl wrote:
   Also, seems that not many people are aware of "process substitution"
   in bash: you do something like "diff (ls dir1) (ls dir2)", and bash
   runs two ls's, each writing to a FIFO, and diff gets the names of
   these two FIFOs as parameters. Output redirection also works. I'm not
   sure how portable it is, though.
  
  1.
  [08:05:37 /tmp]$ diff  (ls ~/setiathome/) (ls ~/setiathome/amos/)
  bash: syntax error near unexpected token `(l'
  [08:06:04 /tmp]$ 
  
  Ache, the space there is significant:
  
  [08:17:12 /tmp]$ diff (ls ~/setiathome/) (ls ~/setiathome/amos/)
 
 Yeah... Otherwise it's redirection.
 




I am confused. Without the space it is not a redirection? Is there a 
difference between a FIFO and a redirection?



 
  2.
  This will only work if the "main" process (diff in this example) does not need 
  to seek the input since it can not do it with a FIFO. Or am I missing 
  something?
 
 True... You can't. It would've been nice if Bash had the option to use
 temporary files rather than FIFOs... But I don't know if it's needed
 that often.
 
 Just tried: both nvi and vim cope fine, Emacs refuses to read it (at
 least with default setup and switches). Less requires you to use -f. 
 
 
   - Adi Stav
 
 =
 To unsubscribe, send mail to [EMAIL PROTECTED] with
 the word "unsubscribe" in the message body, e.g., run the command
 echo unsubscribe | mail [EMAIL PROTECTED]
 

-- 

Shaul Karl [EMAIL PROTECTED]



=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]




Cool shell tricks (was: Re: file system questions)

2000-10-20 Thread Adi Stav

On Tue, Oct 17, 2000 at 04:59:48PM +0200, guy keren wrote:
 there is a dirty method you could use. every once in a while (perhaps even
 via a cron job), execute the command:
 
 :/path/to/.xsession-error

Cool.

I love these little shell tricks... I'm personally particularly fond
of the old "(cd dir1; tar c) | (cd dir2; tar xv)" thing, but it's been
discussed here extensively before.

Also, seems that not many people are aware of "process substitution"
in bash: you do something like "diff (ls dir1) (ls dir2)", and bash
runs two ls's, each writing to a FIFO, and diff gets the names of
these two FIFOs as parameters. Output redirection also works. I'm not
sure how portable it is, though.

Does anyone else like these tricks? I'd love to hear about other
people's.


- Adi Stav

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]