Eu preciso criar um comando para concatenar outros valores de string menores:
function processES {
local status=$KO_UNKNOWN
local method="GET"
if [ ! -z $1 ]; then method=$1; fi
local curl="curl -s -X${method} "$2
if [ ! -z "$3" ]; then curl+=" -d '$3'"; fi
local jq="jq 'if has(\"error\") then .error.type elif has(\"acknowledged\") then \"ok\" else \"unknown\" end'"
local sed="sed -e 's/^\"//' -e 's/\"$//'"
local command="$curl | $jq | $sed" <<<<<<<<<<<< CONCATENATION
echo $command
local r=$(command)
e_warning $r
if [ $? == $RESPONSE_OK ]; then
status=$OK
elif [ $? == $RESPONSE_ERROR_IDXALDEXISTS ]; then
status=$KO_IDXALDEXISTS
else
status=$KO_UNKNOWN
fi
return $status
}
O comando concatenado é bem construído:
curl -s -XPUT http://localhost:9201/living_v1 | jq 'if has("error") then .error.type elif has("acknowledged") then "ok" else "unknown" end' | sed -e 's/^"//' -e 's/"$//'
O problema é que não consigo ver como executá-lo e obter o resultado e configurá-lo em uma variável.
Alguma idéia?
Tags shell-script