Quantcast
Channel: Why does assigning a variable with command substitution, and then echoing that variable, always fail? - Super User
Browsing all 10 articles
Browse latest View live

Answer by sqrt-1 for why does assigning a var with command substitution then...

Based on the link provided by @DavidPostill, I would useecho "Hello world!" > test.txt && TEST="$(cat test.txt)" && echo "$TEST"

View Article



Answer by DavidPostill for why does assigning a var with command substitution...

Why does the following not work in bash?echo "Hello world!" > test.txt && TEST="$(cat test.txt)" echo "$TEST"If you run it though ShellCheck – shell script analysis tool it will tell you...

View Article

why does assigning a var with command substitution then echoing that var...

Why does the following not work in bash?# ensure TEST is unsetexport TEST=''echo "Hello world!" > test.txt && TEST="$(cat test.txt)" echo "$TEST"It always returns a blank line for some...

View Article

Answer by TOOGAM for why does assigning a var with command substitution then...

Not to conflict with any of the other pre-existing answers, but I thought a step-by-step analysis may help. (u1686_grawity's answer looks accurate, but I thought this might be more clear...)# ensure...

View Article

Answer by u1686_grawity for why does assigning a var with command...

It doesn't work because $var expansions are performed by the shell before the command line is run, i.e. not by the 'echo' command.Meanwhile, VAR=value somecommand is not a regular assignment – it is...

View Article


Answer by TOOGAM for Why does assigning a variable with command substitution,...

Not to conflict with any of the other pre-existing answers, but I thought a step-by-step analysis may help. (u1686_grawity's answer looks accurate, but I thought this might be more clear...)# ensure...

View Article

Answer by u1686_grawity for Why does assigning a variable with command...

It doesn't work because $var expansions are performed by the shell before the command line is run, i.e. not by the 'echo' command.Meanwhile, VAR=value somecommand is not a regular assignment – it is...

View Article

Answer by sqrt-1 for Why does assigning a variable with command substitution,...

Based on the link provided by @DavidPostill, I would useecho "Hello world!" > test.txt && TEST="$(cat test.txt)" && echo "$TEST"DUE EDITAs many users rightly pointed out, mine is far...

View Article


Answer by DavidPostill for Why does assigning a variable with command...

Why does the following not work in bash?echo "Hello world!" > test.txt && TEST="$(cat test.txt)" echo "$TEST"If you run it though ShellCheck – shell script analysis tool it will tell you...

View Article


Why does assigning a variable with command substitution, and then echoing...

Why does the following not work in Bash?# Ensure TEST is unsetexport TEST=''echo "Hello world!" > test.txt && TEST="$(cat test.txt)" echo "$TEST"It always returns a blank line for some...

View Article
Browsing all 10 articles
Browse latest View live




Latest Images