String command not going to variable.

Here you can discuss every aspect of Debian. Note: not for support requests!

String command not going to variable.

Postby Munty Scruntfundle » 2019-02-11 19:45

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.
Munty Scruntfundle
Posts: 54
Joined: 2018-11-27 16:53

Re: String command not going to variable.

Postby bw123 » 2019-02-11 19:55

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
User avatar
Posts: 3786
Joined: 2011-05-09 06:02

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 10 guests