Subj : Re: help with bash prog and links To : comp.os.linux From : Vilmos Soti Date : Thu Sep 09 2004 04:13 pm "JV" writes: > in trying to make a bash program that can evaluate a symbolic link and act > accordingly > psuedo code follows > > if ./lnk = softlink(targ1) { > rm ./lnk > ln -s ./targ2 ./lnk > echo "lnk = targ2" > elif ./lnk == softlink(targ2) { > rm ./lnk > ln -s ./targ1 ./lnk > echo "lnk = targ1" > fi What do you try to accomplish? What is targ1? And what is ./lnk's relationship to targ1? Also, what does softlink() do? It returns true if the argument is a symlink? Are you trying to do something that ./lnk points to one target, and you want to point it to the another one? Like a a toggle? Anyways, to read the target of a symlink, use the "readlink" program. Here is a code (not tested) what might do what you want. [ ! -L lnk ] && return # returns unless symlink target=$(readlink lnk) # get link's target to $target if [ "$target" = "targ1" ]; then # obvious from here rm lnk ln -s targ2 lnk elif [ "$target" = "targ2" ]; then rm lnk ln -s targ1 lnk fi Vilmos .