euglug.org

[Eug-lug] stupid bash question

작성자

카테고리:



Allen BrownTue Mar 15 11:00:52 PST 2005

Actually, that doesn't work.
   cdlast foo bar/foobar
tries to go to ".".

In general I prefer to use $() syntax rather than the older ``
syntax. I think it is more readable.  And it is recursive, where
`` is not.  Also, using $() syntax means that you don't need to
escape the inner quotes.  The function below does the right thing
as far as I know.

function cdlast { cd "$(dirname "$_")"; }
-- 
Allen Brown
   work: Agilent Technologies      non-work: http://www.peak.org/~abrown/
         allen_brown at agilent.com	            abrown at peak.org
   Television--a medium.  So called because it is neither rare
   nor well done. ---Ernie Kovacs


Bob Miller wrote:
> Bob Miller wrote:
> 
> 
>>function cdlast { cd `dirname $_`; }
> 
> 
> Correction:
> 
> function cdlast { cd "`dirname \"$_\"`"; }
> 
> Now it works even if the path has spaces or other punctuation in it.
> And it looks slightly less obvious. (-:
>