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

1 Answer 1

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
    Commented Jul 20, 2020 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. Commented Jul 20, 2020 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
    Commented Jul 20, 2020 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
    Commented Jul 20, 2020 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
    Commented Jul 21, 2020 at 11:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .