Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash: pass multiple parameters from a single variable

Tags:

bash

In a bash call I want to put some constant parameters to a variable and don't lose StdOut & StdErr inside a pipe.

I have a call

git fetch origin "ref1:ref1" "ref2:ref2" "ref3:ref3"

Let's I'll put those constant values to a variable

fetch_refspec="'ref1:ref1' 'ref2:ref2' 'ref3:ref3'"

I see a solution to use a pipe, but I'm afraid to lose the output somehow. And I do not want to use files for a caching (tee command).

echo $refs | xargs git origin

I don't understand how to do this stuff cleverly. Or if it possible at all.
Later I want to put the output to a variable and analyze it.

like image 320
it3xl Avatar asked Oct 13 '25 10:10

it3xl


1 Answers

Don't use a variable, use an array!

declare -a gitArgs=("ref1:ref1" "ref2:ref2" "ref3:ref3")

and pass it to the command you need,

git origin "${gitArgs[@]}"
like image 163
Inian Avatar answered Oct 15 '25 00:10

Inian