I am trying to understand an already written Shell script and I have encountered following line.
while [ -h "$SOURCE" ];
What I need to know is the meaning of -h
As for additional information:
$SOURCE = ./my-script.sh
The -h is not an option to the while keyword, but to the [ (and test) utility. The meaning of the option is described in the manual for either test, [ or of your shell (since these are commonly built-in utilities), see man test.
It's a standard option for test and [, and the POSIX standard describes it like so:
-h pathnameTrue if
pathnameresolves to an existing directory entry for a symbolic link. False ifpathnamecannot be resolved, or ifpathnameresolves to an existing directory entry for a file that is not a symbolic link. If the final component ofpathnameis a symbolic link, that symbolic link is not followed.
In short, it evaluates to true if the given pathname is a symbolic link, so your while loop would loop until the value in the variable SOURCE no longer refers to a symbolic link.