Skip to main content
clarified answer after talking to terdon in chat
Source Link
terdon
  • 252.7k
  • 69
  • 481
  • 719

The first thing to understand is that some commands allow multiple arguments and some do not. While touch allows multiple arguments, ping does not. curl is a special case (see below). In the case of brace expansion and ping, it isthe braces are expanding out andto multiple and calling ping with multiple arguments, which ping will not do. A for loop is a better solution in this case. Also, the braces in curl are a special case (see below).

The answer to "which commands can use brace expansion" is all and none. The brace expansion is done by the shell, before passing the expanded output to the command. In other words, the command being launched is completely irrelevant. The expansion of foo{bar,baz} to foobar foobaz is done by the shell before launching the command and passing the expanded string as parameters to it.

However, brace expansion does not occur inside quotes. In other words, both "{,,,}" and "{a,b,c}" remain as strings and are not expanded:

$ echo "{,,,}" {,,,} $ echo "{a,b,c}" {a,b,c} 

To get expansion to work, you should remove the quotes:

$ echo {,,,} ## this expands to a blank string, so this is what is printed $ echo {a,b,c} a b c 

This is documented in the relevant section of man bash (emphasis mine):

Brace expansion is performed before any other expansions, and any characters special to other expansions are preserved in the result. It is strictly textual. Bash does not apply any syntactic interpretation to the context of the expansion or the text between the braces.

A correctly-formed brace expansion must contain unquoted opening and closing braces, and at least one unquoted comma or a valid sequence expression.

Now, the reason you are confused is that curl actually has its own parser and that also handles brace expansion. This is done independently of the shell and is explained in man curl:

You can specify multiple URLs or parts of URLs by writing part sets within braces as in:

 http://site.{one,two,three}.com 

So, any command can work with brace expansion since it isn't actually the command working with it, but the shell that expands the expression in the braces before calling the command. Curl is confusing because it has its own, similar feature.

The first thing to understand is that some commands allow multiple arguments and some do not. touch allows multiple arguments, ping does not. curl is a special case (see below). In the case of brace expansion and ping, it is expanding out and calling ping with multiple arguments, which ping will not do. A for loop is a better solution in this case.

The answer is all and none. The brace expansion is done by the shell, before passing the expanded output to the command. In other words, the command being launched is completely irrelevant. The expansion of foo{bar,baz} to foobar foobaz is done by the shell before launching the command and passing the expanded string as parameters to it.

However, brace expansion does not occur inside quotes. In other words, both "{,,,}" and "{a,b,c}" remain as strings and are not expanded:

$ echo "{,,,}" {,,,} $ echo "{a,b,c}" {a,b,c} 

To get expansion to work, you should remove the quotes:

$ echo {,,,} ## this expands to a blank string, so this is what is printed $ echo {a,b,c} a b c 

This is documented in the relevant section of man bash (emphasis mine):

Brace expansion is performed before any other expansions, and any characters special to other expansions are preserved in the result. It is strictly textual. Bash does not apply any syntactic interpretation to the context of the expansion or the text between the braces.

A correctly-formed brace expansion must contain unquoted opening and closing braces, and at least one unquoted comma or a valid sequence expression.

Now, the reason you are confused is that curl actually has its own parser and that also handles brace expansion. This is done independently of the shell and is explained in man curl:

You can specify multiple URLs or parts of URLs by writing part sets within braces as in:

 http://site.{one,two,three}.com 

So, any command can work with brace expansion since it isn't actually the command working with it, but the shell that expands the expression in the braces before calling the command. Curl is confusing because it has its own, similar feature.

The first thing to understand is that some commands allow multiple arguments and some do not. While touch allows multiple arguments, ping does not. In the case of ping, the braces are expanding to multiple and calling ping with multiple arguments, which ping will not do. A for loop is a better solution in this case. Also, the braces in curl are a special case (see below).

The answer to "which commands can use brace expansion" is all and none. The brace expansion is done by the shell, before passing the expanded output to the command. In other words, the command being launched is completely irrelevant. The expansion of foo{bar,baz} to foobar foobaz is done by the shell before launching the command and passing the expanded string as parameters to it.

However, brace expansion does not occur inside quotes. In other words, both "{,,,}" and "{a,b,c}" remain as strings and are not expanded:

$ echo "{,,,}" {,,,} $ echo "{a,b,c}" {a,b,c} 

To get expansion to work, you should remove the quotes:

$ echo {,,,} ## this expands to a blank string, so this is what is printed $ echo {a,b,c} a b c 

This is documented in the relevant section of man bash (emphasis mine):

Brace expansion is performed before any other expansions, and any characters special to other expansions are preserved in the result. It is strictly textual. Bash does not apply any syntactic interpretation to the context of the expansion or the text between the braces.

A correctly-formed brace expansion must contain unquoted opening and closing braces, and at least one unquoted comma or a valid sequence expression.

Now, the reason you are confused is that curl actually has its own parser and that also handles brace expansion. This is done independently of the shell and is explained in man curl:

You can specify multiple URLs or parts of URLs by writing part sets within braces as in:

 http://site.{one,two,three}.com 

So, any command can work with brace expansion since it isn't actually the command working with it, but the shell that expands the expression in the braces before calling the command. Curl is confusing because it has its own, similar feature.

clarified answer after talking to terdon in chat
Source Link

The first thing to understand is that some commands allow multiple arguments and some do not. touch allows multiple arguments, ping does not. curl is a special case (see below). In the case of brace expansion and ping, it is expanding out and calling ping with multiple arguments, which ping will not do. A for loop is a better solution in this case.

The answer is all and none. The brace expansion is done by the shell, before passing the expanded output to the command. In other words, the command being launched is completely irrelevant. The expansion of foo{bar,baz} to foobar foobaz is done by the shell before launching the command and passing the expanded string as parameters to it.

However, brace expansion does not occur inside quotes. In other words, both "{,,,}" and "{a,b,c}" remain as strings and are not expanded:

$ echo "{,,,}" {,,,} $ echo "{a,b,c}" {a,b,c} 

To get expansion to work, you should remove the quotes:

$ echo {,,,} ## this expands to a blank string, so this is what is printed $ echo {a,b,c} a b c 

This is documented in the relevant section of man bash (emphasis mine):

Brace expansion is performed before any other expansions, and any characters special to other expansions are preserved in the result. It is strictly textual. Bash does not apply any syntactic interpretation to the context of the expansion or the text between the braces.

A correctly-formed brace expansion must contain unquoted opening and closing braces, and at least one unquoted comma or a valid sequence expression.

Now, the reason you are confused is that curl actually has its own parser and that also handles brace expansion. This is done independently of the shell and is explained in man curl:

You can specify multiple URLs or parts of URLs by writing part sets within braces as in:

 http://site.{one,two,three}.com 

So, any command can work with brace expansion since it isn't actually the command working with it, but the shell that expands the expression in the braces before calling the command. Curl is confusing because it has its own, similar feature.

The answer is all and none. The brace expansion is done by the shell, before passing the expanded output to the command. In other words, the command being launched is completely irrelevant. The expansion of foo{bar,baz} to foobar foobaz is done by the shell before launching the command and passing the expanded string as parameters to it.

However, brace expansion does not occur inside quotes. In other words, both "{,,,}" and "{a,b,c}" remain as strings and are not expanded:

$ echo "{,,,}" {,,,} $ echo "{a,b,c}" {a,b,c} 

To get expansion to work, you should remove the quotes:

$ echo {,,,} ## this expands to a blank string, so this is what is printed $ echo {a,b,c} a b c 

This is documented in the relevant section of man bash (emphasis mine):

Brace expansion is performed before any other expansions, and any characters special to other expansions are preserved in the result. It is strictly textual. Bash does not apply any syntactic interpretation to the context of the expansion or the text between the braces.

A correctly-formed brace expansion must contain unquoted opening and closing braces, and at least one unquoted comma or a valid sequence expression.

Now, the reason you are confused is that curl actually has its own parser and that also handles brace expansion. This is done independently of the shell and is explained in man curl:

You can specify multiple URLs or parts of URLs by writing part sets within braces as in:

 http://site.{one,two,three}.com 

So, any command can work with brace expansion since it isn't actually the command working with it, but the shell that expands the expression in the braces before calling the command. Curl is confusing because it has its own, similar feature.

The first thing to understand is that some commands allow multiple arguments and some do not. touch allows multiple arguments, ping does not. curl is a special case (see below). In the case of brace expansion and ping, it is expanding out and calling ping with multiple arguments, which ping will not do. A for loop is a better solution in this case.

The answer is all and none. The brace expansion is done by the shell, before passing the expanded output to the command. In other words, the command being launched is completely irrelevant. The expansion of foo{bar,baz} to foobar foobaz is done by the shell before launching the command and passing the expanded string as parameters to it.

However, brace expansion does not occur inside quotes. In other words, both "{,,,}" and "{a,b,c}" remain as strings and are not expanded:

$ echo "{,,,}" {,,,} $ echo "{a,b,c}" {a,b,c} 

To get expansion to work, you should remove the quotes:

$ echo {,,,} ## this expands to a blank string, so this is what is printed $ echo {a,b,c} a b c 

This is documented in the relevant section of man bash (emphasis mine):

Brace expansion is performed before any other expansions, and any characters special to other expansions are preserved in the result. It is strictly textual. Bash does not apply any syntactic interpretation to the context of the expansion or the text between the braces.

A correctly-formed brace expansion must contain unquoted opening and closing braces, and at least one unquoted comma or a valid sequence expression.

Now, the reason you are confused is that curl actually has its own parser and that also handles brace expansion. This is done independently of the shell and is explained in man curl:

You can specify multiple URLs or parts of URLs by writing part sets within braces as in:

 http://site.{one,two,three}.com 

So, any command can work with brace expansion since it isn't actually the command working with it, but the shell that expands the expression in the braces before calling the command. Curl is confusing because it has its own, similar feature.

Source Link
terdon
  • 252.7k
  • 69
  • 481
  • 719

The answer is all and none. The brace expansion is done by the shell, before passing the expanded output to the command. In other words, the command being launched is completely irrelevant. The expansion of foo{bar,baz} to foobar foobaz is done by the shell before launching the command and passing the expanded string as parameters to it.

However, brace expansion does not occur inside quotes. In other words, both "{,,,}" and "{a,b,c}" remain as strings and are not expanded:

$ echo "{,,,}" {,,,} $ echo "{a,b,c}" {a,b,c} 

To get expansion to work, you should remove the quotes:

$ echo {,,,} ## this expands to a blank string, so this is what is printed $ echo {a,b,c} a b c 

This is documented in the relevant section of man bash (emphasis mine):

Brace expansion is performed before any other expansions, and any characters special to other expansions are preserved in the result. It is strictly textual. Bash does not apply any syntactic interpretation to the context of the expansion or the text between the braces.

A correctly-formed brace expansion must contain unquoted opening and closing braces, and at least one unquoted comma or a valid sequence expression.

Now, the reason you are confused is that curl actually has its own parser and that also handles brace expansion. This is done independently of the shell and is explained in man curl:

You can specify multiple URLs or parts of URLs by writing part sets within braces as in:

 http://site.{one,two,three}.com 

So, any command can work with brace expansion since it isn't actually the command working with it, but the shell that expands the expression in the braces before calling the command. Curl is confusing because it has its own, similar feature.