What this construct does in Bash

Viewed 44
$ echo [1,2,"abc",4]

Output:

c

I came across this while trying to pass this string to my Node.js program as an argument. Instead Some weird Bash magic happened. I believe it is explained "somewhere" in lengthy man bash but I cannot find anything yet.

1 Answers

This is just a single character range glob written in a funny way.

[abc] matches one of the characters a, b or c.

[1,2,"abc",4] matches one of the characters a, b ,c,1,2,4 or comma, and is equivalent to [abc124,]

Since you have a directory named c, it matches and gets printed.

Related