Hi Victor,

> > while [[ $f ]]; do ls -ld "$f"; f=${f%/*}; done; ls -ld /
>
> I had not come across that bash function ${f%/*} before.

There are various substitutions shells like bash(1) provide on variable
expansion that avoid having to kick off a sed.  Here's some variations.

    $s                  foo,bar,xyzzy
    ${s#*,}             bar,xyzzy
    ${s##*,}            xyzzy
    ${s%,*}             foo,bar
    ${s%%,*}            foo
    ${s/bar/prohibit}   foo,prohibit,xyzzy
    ${s/o}              fo,bar,xyzzy
    ${s//o}             f,bar,xyzzy
    ${s//[aeiouy]/V}    fVV,bVr,xVzzV

`#' and `%' are mnemonic in that `#$%' are on `345' on the keyboard with
`#' matching at the start of the variable and `%' matching at the end.
`/' is obviously traditional at this point, being the common `start of
pattern' character in ed(1)'s `s' substitute command.

The easy way to get a refresher is `man bash' and search for `##'.
Note, the pattern to search for isn't a regexp, more a glob.

Cheers, Ralph.

-- 
Next meeting:  Bournemouth, Tuesday, 2012-10-02 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread on mailing list:  mailto:[email protected]
How to Report Bugs Effectively:  http://goo.gl/4Xue

Reply via email to