I have the following code:
#bin/sh
symbolic=''
target=''
ls -la | grep "\->" | while read line
do
target=${line##* }
done
which will print out all targets files (where symbolic links point to).
Now, I would like to add the following constraints:
- parse the symbolic link file name (the word before ->) into the var "symbolic". (I would like to treat it as the 3rd last word of the string)
- only parse the symbolic link which points to a valid/existing place.
If I don't want to use "echo | awk", are there any other ways to achieve this?
Thanks!
Update & Final Solutions
#bin/sh
find . -maxdepth 1 -type l -xtype d | while read line
do
symlink=$line
target=$(readlink line)
done