0

I am new to bash and am trying to understand a script I have been passed. Within the script, I have the following variable:

site_source="${site_host[$i]}:public_html"

Can anyone confirm what the colon means here? I am needing to change the path stored within this variable to a root path, so had thought that removing the :public_html part would achieve this (it doesn't).

2
  • Simple concatenation. ${site_host[$i]} + ":" + "public_html" Commented Mar 10, 2023 at 9:41
  • Did you take a look at what the variable contains after that? Because it might give a very good indication of what happens.
    – ilkkachu
    Commented Mar 10, 2023 at 10:28

1 Answer 1

1

This is a simple concatenation:

${site_host[$i]} + ":" + "public_html"

To be not confused with parameter expansions

Parameter Expansion expands parameters: $foo, $1. You can use it to perform string or array operations: "${file%.mp3}", "${0##*/}", "${files[@]: -4}". They should always be quoted.
See: http://mywiki.wooledge.org/BashFAQ/073 and "Parameter Expansion" in man bash.
Also see http://wiki.bash-hackers.org/syntax/pe

1
  • Good advice about always quoting! Note that in scalar variable assignments (as in the OP's site_source=...), one shouldn't use "${array[@]}" which does not make sense as scalar variables can only hold one value. One could use "${array[*]}" which joins the elements with the first character of $IFS. You'd use @` in array variable assignments: array=( "${other_array[@]}" ), where quotes are even more important than in the scalar assignment case. Commented Mar 10, 2023 at 14:57

You must log in to answer this question.

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