A mistake most bash beginners make

It's the array variable expantion. here is an example:

x=( a b "c d" );

echo ${x[@]}

in this example a beginner would thinkg that ${x[@]} would be expanded to 3 fields but no. It would be expanded into 4 field a,b,c,d . It's very confusing. however to prevent it we just quote the parameter expansion like "${x[@]}" and now it would only expand to 3 fields :)

hope you learned something new.

Posted in: s/bash

๐Ÿš€ random2934

2024-08-21 ยท 2 years ago ยท ๐Ÿ‘ lanterm, nerd, coldcalzone

Proxied content from gemini://bbs.geminispace.org/s/bash/19148 (external content)

Gemini request details:

Original URL
gemini://bbs.geminispace.org/s/bash/19148
Status code
Success
Meta
text/gemini; charset=utf-8
Proxied by
kineto

Be advised that no attempt was made to verify the remote SSL certificate.