1
a=HDH b=udud c=jsjsj bash secondscript

The command above works. I'd like to save the assignments in a variable, like so:

value="\
    a=HDH \
    b=udud \
    c=ududj \
    "
$value bash secondscript

But it gives an error:

test.sh: line 9: a=HDH: command not found

Why? What can I do instead?

6
  • 1
    Assignments are identified before any expansion happens. Commented May 27, 2020 at 12:01
  • Ok so what should i do then ? Any workaround to achieve my goal Commented May 27, 2020 at 12:02
  • For an explanation of why you can't save assignments in a variable see my writeup here: stackoverflow.com/questions/61898254/…. Commented May 27, 2020 at 12:42
  • eval $value bash secondscript Commented May 27, 2020 at 13:31
  • @alecxs eval is working only when value is an array Commented May 27, 2020 at 14:51

1 Answer 1

3

bash's taking first item a=HDH as a command, what you need is :

value=(
  "a=HDH"
  "b=udud"
  "c=ududj"
)
env "${value[@]}" bash secondscript
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.