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

[no subject]



    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


</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<ul><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><a name="00542" href="msg00542.html">[ale] Looking for a one line script</a></strong>
<ul><li><em>From:</em> james.sumners at gmail.com (James Sumners)</li></ul></li>
</ul></li></ul>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="00533" href="msg00533.html">[ale] Looking for a one line script</a></strong>
<ul><li><em>From:</em> james.sumners at gmail.com (James Sumners)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00536.html">[ale] Looking for a one line script</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00538.html">[ale] Messages hanging fetchmail</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00536.html">[ale] Looking for a one line script</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00542.html">[ale] Looking for a one line script</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00537"><strong>Date</strong></a></li>
<li><a href="threads.html#00537"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>