Bhavya Arora
Bhavya Arora

Reputation: 800

Output of cut, value: command not found

I have a script .

...
join -1 3 -2 3 $fileName1 $fileName2 > temp.txt
($(cut -d' ' -f1 temp.txt))
.    
.

I expect the output to be

c

but I get

c: command not found

I am really new to bash scripting, any help would be appreciated :)

Upvotes: 0

Views: 325

Answers (2)

Fazlin
Fazlin

Reputation: 2337

You are running cut command once within $() and then trying to execute the output of cut (in your case c i supppose) by putting another set of ().

So either run cut command alone if you want the output to be printed on stdout

cut -d' ' -f1 temp.text

or if you want to get the output in variable

var=$(cut -d' ' -f1 temp.text)
echo $var

Reference: command substitution (Thanks @sjsam)

Upvotes: 2

Barmar
Barmar

Reputation: 780889

Just write:

cut -d' ' -f1 temp.text

When you put a command in $(), it substitutes the output back into the command line. And then, since this is at the beginning of the command line, it tries to execute the output as if it's another shell command.

Upvotes: 2

Related Questions