0

I'm reading this line from PostgreSQL's docker image repo.

PGHOST= PGHOSTADDR= "${query_runner[@]}" "$@"

I'm so confused why it has two var= pattern in one line. I can understand that ${query_runner[@]} will gives the output of executing the command represented by query_runner, but which variable should this output be assigned to? Also, what does it mean by $@ in this case?

IsaIkari
  • 1,002
  • 16
  • 31
  • `var=` is equivalent to `var=''` – 0x5453 Sep 10 '21 at 17:34
  • `var= somecommand` does not change `var` except temporarily _while `somecommand` is running_. It is **not** how one saves `somecommand`'s output into a variable. – Charles Duffy Sep 10 '21 at 17:38
  • @CharlesDuffy Thanks! But still I'm confused how to interpret `PGHOST= PGHOSTADDR= "${query_runner[@]}" "$@"`. Does it mean that when `query_runner[@]` is running, `PGHOSTADDR` is temporarily changed (to what)? But how it has something to do with `PGHOST`? – IsaIkari Sep 10 '21 at 17:42
  • @IsaKyodo, both `PGHOST` and `PGHOSTADDR` are temporarily changed to contain empty strings for the duration of `query_runner`'s execution. – Charles Duffy Sep 10 '21 at 18:02
  • 1
    @IsaKyodo, ...presumably, this is to prevent environment variables from overriding whatever configuration is set via dotfiles / defaults / etc. – Charles Duffy Sep 10 '21 at 18:05
  • @CharlesDuffy Thanks so much, I'm so much clearer now. One last question -- since this line has a `"$@"` at the very end, should I interpret it as: 1. run `query_runner`; 2. run what is in `$@`; 3. When running 1 and 2, set `PGHOST` and `PGHOSTADDR` to empty strings. Do you think this is correct? – IsaIkari Sep 10 '21 at 18:13
  • 1
    @IsaKyodo, `"$@"` (which is an array consisting of the arguments to the current script/function/etc) is extra arguments to pass to whatever command is constructed from the contents of the array `"${query_runner[@]}"`. – Charles Duffy Sep 10 '21 at 18:31
  • @CharlesDuffy, ahh. I see, so I should interprete `"${query_runner[@]}" "$@"` as one execution. Thanks so much! – IsaIkari Sep 10 '21 at 18:33

0 Answers0