What does -L $package_path mean or do in the following code?

PACKAGES=(a b c)
COLORS=(32 33 34 35 36 32)
PACKAGE_LINK_PATHS=(false false false false false false)

esc=$(printf '\e')
for index in "${!PACKAGES[@]}"
    if  [ -L $package_path ]; then
        if [ $unlinkPackages = true ]; then
            printf "Unlinking ${package_name}\n"
            # Cache the currently linked package path
            PACKAGE_LINK_PATHS[$index]=$(readlink $package_path)
        rm -rf $package_path
if [ -L

means "test for symlink".

The printf "Unlinking ${package_name}\n" is a big clue ;)

And man bash explains it too (search for -L):

-L file    True if file exists and is a symbolic link.
  • I have tried to verify in the bash, but this is what I got: ➜ exec bash | bash-3.2$ -L node_modules | bash: -L: command not found – Lusha Li Jul 20 '20 at 18:32
  • @LushaLi The command being used is [ rather than -L. The [ command accepts various tests, of which -L is one. See the output of help [ and help test (run in bash) for details. – Eliah Kagan Jul 20 '20 at 19:48
  • @LushaLi that is not how that works. man bash and what Eliah stated help [ will show what [ does. -L is just a code for link (symlink) – Rinzwind Jul 20 '20 at 20:20
  • Oh, I see. Thanks a lot.@Eliah Kagan and Rinzwind When designing the bash, why do we use "[ ]" in bash? Won't wrapping the expression with "( )" be enough? – Lusha Li Jul 20 '20 at 22:49
  • Well... that was a design decision by the creator. Bash is old. Probably [ and ] where not used for anything back then. – Rinzwind Jul 21 '20 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.