[ale] Looking for a one line script

Fletch fletch at phydeaux.org
Mon Jun 13 20:32:55 EDT 2005


>>>>> "James" == James Sumners <james.sumners at gmail.com> writes:

    James> I need to get the base path of a filename. For example, if
    James> I have "/path/to/some/random/file.ext" I need to trim off
    James> "file.ext" so that I am left with
    James> "/path/to/some/random/". However, the filename could
    James> contain spaces and other odd characters. Any suggestions?

Both basename and dirname should handle spaces fine.

freebie:/tmp 625> mkdir -p "foo bar"/baz
freebie:/tmp 626> touch "foo bar"/baz/boink
freebie:/tmp 627> i="$( basename /tmp/foo\ bar/baz/boink )"
freebie:/tmp 628> print "|$i|"
|boink|
freebie:/tmp 629> i="$( dirname /tmp/foo\ bar/baz/boink )"
freebie:/tmp 630> print "|$i|"
|/tmp/foo bar/baz|

-- 
Fletch                | "If you find my answers frightening,       __`'/|
fletch at phydeaux.org|  Vincent, you should cease askin'          \ o.O'
                      |  scary questions." -- Jules                =(___)=
                      |                                               U



More information about the Ale mailing list