else
set lnk = $(readlink -f <path> | cut -d '/' -f7)
echo "$lnk"
if [[ "$lnk" == "$ver" ]]
When I run the above on command line , the execution seems to be fine and I get the desired output. But when I try to assign it to a variable within a loop , it doesnt get assigned.Hence the "if condition" after the variable assignment doesnt get evaluated.
A bit difficult to believe. In bash , set is not used to assign variables, be it interactively or in a script. Simply drop it. And, remove the spaces around the = sign.
By "within a loop" do you happen to mean "behind a pipe?" also known as "inside a subshell"? That will not work. Variables inside a subshell do not get communicated to outside the subshell.
Please show us your entire script instead of showing us one line at a time.
It seems highly likely that you are setting the variable you want inside a sub-shell and that makes the assigned value invisible outside of that sub-shell. But we can't know that until we can see all of your code.
gives an empty string.
(A subshell and/or a wrong assignment would cause additional problems of course.)
If the question is for a better debugging, then I suggest to repeat the readlink -f <path> command without a following pipe. Maybe framed by some "debug" text: