String command not going to variable.

Here you can discuss every aspect of Debian. Note: not for support requests!
Post Reply
Munty Scruntfundle
Posts: 54
Joined: 2018-11-27 16:53

String command not going to variable.

#1 Post 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.

User avatar
Posts: 3786
Joined: 2011-05-09 06:02

Re: String command not going to variable.

#2 Post 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?


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

Post Reply