0

If I assign a variable:

testThis='echo "This is a test"'

If I use $testThis, it works in a script.

But, what if I want to skip a line ? So I try:

testThis='echo; echo "This is a test"'

and this fails!

Can't figure it out after much effort trying $() command substitution and all sorts of quoting.

1

1 Answer 1

2

A parameter expansion is not reparsed. The following

testThis='echo; echo "This is a test"'
$testThis

is equivalent to

echo ';' echo \"This is a test\"

The semicolon and the double quotes are both literal parts off the string, not shell syntax. After word-splitting and quote removal, the shell identifies the command echo with six arguments:

  1. ;
  2. echo
  3. "This
  4. is
  5. a
  6. test"

Use a function instead:

testThis () {
    echo; echo "This is a test"
}

testThis
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.