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 }')
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With