Re: pipes ifs and suggestions
- From: DBaldi <davide@none>
- Date: Fri, 12 Jun 2009 17:11:52 +0200
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
.
- References:
- pipes ifs and suggestions
- From: DBaldi
- Re: pipes ifs and suggestions
- From: pk
- pipes ifs and suggestions
- Prev by Date: Re: awk / building sums of values in different lines
- Next by Date: Re: pipes ifs and suggestions
- Previous by thread: Re: pipes ifs and suggestions
- Next by thread: Re: pipes ifs and suggestions
- Index(es):
Relevant Pages
|