Eval выполняет команду, но замена команды прерывает ееLinux

Ответить
Гость
 Eval выполняет команду, но замена команды прерывает ее

Сообщение Гость »


I have the following code

#!/bin/sh echo "intented command:" jq -n --argjson bar '{"test":"asdf"}' '$bar | .test' foo="{\"test\":\"asdf\"}" command="jq -n --argjson bar '$foo' '\$bar | .test'" echo "Built command:" echo $command echo "Command execution with eval:" eval $command echo "Command execution with command substitution:" $($command) The first command works just fine and shows that the usecase is executable, also the outputed command by echo is exactly as in the original command in line 3, so I understand the escaping is working as intended.

eval evaluates the command stored in command just fine, but $($command) fails with the error message

jq: invalid JSON text passed to --argjson Use jq --help for help with command-line options, or see the jq manpage, or online docs at https://stedolan.github.io/jq I would therefore expect that the escaping is somehow changes in $($command) but I could not identify why. Can anybody please explain?


Источник: https://stackoverflow.com/questions/781 ... -breaks-it
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Linux»