Page 1 of 1

String command not going to variable.

Posted: 2019-02-11 19:45
by Munty Scruntfundle
Hi folks.

If I say:

Code: Select all

output="$(ls -l)"
echo output
I get the ls command output, without cr, but I get an output.

If I say:

Code: Select all

output = "$(awk '/Tile/ {match($0, /Tile/); print substr($0, RSTART+5, RLENGTH+20);}' /blender.txt)"
I get an error, command output not found.
The command without the output="$(....)" returns the correct and expected results.

So, why does the second command, which is correct, not work? I'm guessing there's a clash of ' or ) or ", I've tried loads of combinations but I can't get the output into output.

Many thanks.

Re: String command not going to variable.

Posted: 2019-02-11 19:55
by bw123
Silly questions. bash interprets

Code: Select all

$output = anything

as you trying to run the command named output with the flag = and since there is no command named output in your path... there's an error.
output=$(somewhatever) is interpreted assigning a value to a variable. It's different because you didn't put spaces.


Your prior example won't work either, you forgot the $ in echo output, it will just echo the word output.

Pls don;t spam the board with these type posts, I saw at least three really silly posts already, slow down a little?

thanks.

p.s. gosee if linuxzoo is still up it's good