[Top][All Lists]

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

Re: Is there a special variable for the directory where the script is in

From: Bob Proulx
Subject: Re: Is there a special variable for the directory where the script is in?
Date: Fri, 12 Feb 2010 09:53:59 -0700
User-agent: Mutt/1.5.18 (2008-05-17)

Greg Wooledge wrote:
> That leaves names which contain ->.  The tricky part here is that we
> can't easily tell whether an extra -> is in the symbolic link or in
> the target.
> imadev:~$ ln -s tmp 'x -> y'
> imadev:~$ ln -s 'y -> tmp' x
> imadev:~$ ls -ld x*
> lrwxr-xr-x   1 wooledg    pgmr             8 Feb 12 09:28 x -> y -> tmp
> lrwxr-xr-x   1 wooledg    pgmr             3 Feb 12 09:28 x -> y -> tmp
> However, there actually is enough information available to extract
> the desired part.  When we call ls -l, we're passing it the filename
> we're resolving.  So we already know the source name.  Removing the
> source name and the ' -> ' which follows it should leave us with the
> target name.
>     link=$(command ls -l -- "$file"; printf x)
>     link=${link%$'\nx'}
>     remove="$file -> "
>     file=${link#*$remove}

Your solution using the original filename is better but I thought I
would point out that the size of the target value is also displayed by
'ls -l'.  In the above the value "tmp" is 3 characters and "y -> tmp"
is 8 characters and that value is displayed in the size field.  So
even without knowing the filename to be listed the result can be
parsed to extract the target name.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]