Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 }')
like image 953
aa8y Avatar asked Dec 05 '25 14:12

aa8y


2 Answers

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
like image 141
Joe Hildebrand Avatar answered Dec 07 '25 06:12

Joe Hildebrand


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.

like image 42
faho Avatar answered Dec 07 '25 05:12

faho



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!