What does this do in bash: [@]?

Peter Flynn peter at silmaril.ie
Fri Jul 29 19:02:15 UTC 2022


On 29/07/2022 17:40, Bo Berglund wrote:
[...]
> So do I get it right?:
> 
> - Something gets stuffed into a bash variable like URL in the example

So, for example	URL="https://foo.bar.com/somepage?id=xyz&lastpage=35"

> - When this variable is later used as the argument to curl then using [@] as
> shown 

Do you mean	$ curl "${URL[@]}"

> makes the arguments in $URL load separately into curl as a list of
> different arguments

I don't think so. By default the "[@]" is going to split the string into 
arguments based on the default delimiter, the space. You'd need to set 
IFS to "?" in order to split off the "id=xyz&lastpage=35" first, then do 
it again with IFS="&" to get "id=xyz" and "lastpage=35", and then treat 
each of these with IFS="=" to get the variable names and the variable 
values. If you need to do that, there are utilities and libraries which 
provide that facility and return an associative array like

WWW_id		xyz
WWW_lastpage	35

> But if the content of $URL is a long stretch of arguments separated by spaces,

Then it would be invalid as a URL.

> what is then the need for [@]???

I don't personally have a use case for "[@]" so I will leave that to others.

Peter




More information about the ubuntu-users mailing list