Re: pipes ifs and suggestions



pk wrote:
... | xargs grep pattern

It seems able to perform well this task.
Although you're right: think a good way to implement it.

You must quote the string variables, and if you want to test for an empty
string, uze -z:

So bang ! doesn't work inside test!

Finally, you should always quote your variables. Otherwise, your script will
fail as soon as a slightly issue happen like a space in a file name, which
is quite common (and will fail in many other circumstances as well, common
and less common).

WOW it's so evident this is my first script!




Barry Margolin wrote:
**************** this is an exercise in learning the shell control structures. Don't you understand the made-up word "exercitation"?

You're right i'm interested in the structure itself but also functional
piping is worth. Infact i'm attempting to handle multiple files





William Pursell wrote:
Style: many write one liner if bodies as:
test $# -eq 1 && read scanfile

So does && execute next command only IF the previous exit was 0 ?

...
This is an error message. It should be redirected to stderr:
echo ... >&2

...
This is problematic. You need to quote "$scanfile".

Exact!

The desire to have the nice "Matches for file" complicates
the logic a bit, and is really unnecessary. Just do grep -H
as the last command of the script.

It's even chaotic

Rather than this, (which isn't guaranteed to work as
the script may be interrupted before this command
is executed), put:

trap "rm -f $HOME/sinside.tmp" 0

somewhere in the script before you create the file.


There are a ton of things still to learn... BASH I'M COOOOMING !!!

o0
.



Relevant Pages

  • Re: pipes ifs and suggestions
    ... is quite common (and will fail in many other circumstances as well, ... as the last command of the script. ...
    (comp.unix.shell)
  • "after" timer script is never called if the system time is set backwards.
    ... script to update that widget's contents to the latest time. ... for the common use case. ... which I use to change the system clock (via the "date" ... I assume there is a problem with the "after" command I use. ...
    (comp.lang.tcl)
  • Re: [SLE] Executes from Command Line but not Script
    ... >> on the command line and in the script. ... >> fail both times? ... > where script is a file with the single iptables command in it. ...
    (SuSE)
  • Re: [SLE] Executes from Command Line but not Script
    ... >> on the command line and in the script. ... >> Does the script run from the command line ok and fail on boot, ... Does the script run the same shell that you're running under? ...
    (SuSE)
  • Re: command for script
    ... Common to all files: ... I did not use the script for a while and now I am not able to find out ... In that case the shebang line will actually read ... command of that name on your system. ...
    (comp.lang.perl.misc)