Re: Need help with sed statement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, May 4, 2010 at 5:08 PM, Roberto Ragusa <mail@xxxxxxxxxxxxxxxx> wrote:

> The shell syntax is not as difficult as it looks.
> The "#" operator removes a matching part at the beginning (and we are
> matching "*/" so anything followed by a slash).
> There are two variants: "#" and "##"; the first one tries to match
> as few characters as possible; the second one as many as possible.
>
> Same thing with "%" and "%%", but they remove the end of the string.
>
> Some examples:
[snip informative shell examples]
>
> The last one achieves (in two steps) what you were asking me.
>
> Simplicity is many things. The syntax is unfamiliar until you learn it,
> then it becomes "simple". Your method is easier to learn, but not as robust.
> For example, your "basename $foo .txt" will fail if $foo contains a space.
> You need quotes around foo to avoid the problem.

Well spoken...  But I think it often comes down to not what you know
-- and clearly you understand shell syntax -- but what others around
you understand, especially if they need to support the script. In many
cases I've used bash shell arithmetic and a few times have had to rip
it out and replace it with bc, non-Gnu awk, and even perl because of
portability requirements.

In the end it may be a philosophical debate. I certainly appreciate
the examples you gave. As you imply, they are not "clever" so much as
succint, and that is a good quality for a certain class of scripts.

To your point, it's a good idea to quote variables in any case so
"basename "${FOO}" is what I should have posted.

> [rragusa@thinkpad ~]$ foo="try this.txt"; basename $foo .txt
> basename: extra operand `.txt'
> Try `basename --help' for more information.
> [rragusa@thinkpad ~]$ foo="try this.txt"; basename "$foo" .txt
> try this
>
> The shell syntax is immune to the issue because it is an internal
> manipulation of a variable, not an external command involving passing
> arguments.
> That is one manifestation of simplicity, from my point of view. :-)
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux