aa8y
aa8y

Reputation: 3942

Set awk output to variable in fish shell

I am using fish shell and I can't seem to set the output of awk to a variable.

set installed_version (scala -version 2>&1 | awk 'NR==1{ print $5 }')

Any ideas why that's the case?

Edit: This works though

set foo (java -version 2>&1 | awk 'NR==1{ print $3 }')

Upvotes: 3

Views: 4049

Answers (2)

faho
faho

Reputation: 15974

This is fish bug #1949 - fish doesn't run command substitutions in a subprocess, and so leaves stdin connected to the tty. Because of that, some tools don't behave as the should.

Joe Hildebrand's workaround (explicitly redirect </dev/null) is the right thing to do currently.

Upvotes: 1

Joe Hildebrand
Joe Hildebrand

Reputation: 10414

scala is going into the background, starting a REPL because it thinks stdin is a terminal. This works for me:

set installed_version (scala -version 2>&1 < /dev/null | awk 'NR==1{ print $5 }')
echo $installed_version

Upvotes: 4

Related Questions