In fish shell, I want to be able to expand a command substitution or variable as multiple arguments to another command, e.g.:
Without substitution
ls -l -h
Should give the same result as:
ls $(echo '-l -h')
Instead the second one gives an error:
ls: invalid option -- ' '
If I instead do:
eval ls $(echo '-l -h')
It does what I want, it seems.
2 questions then:
- Is using eval in this way actually going to do what I want consistently?
- Is there some other way I should be doing this instead?
I read this question and answer, which is very similar to mine: Command substitution in fish
But the answer is not applicable in my situation.
The real world use case I have is following the instructions for gstreamer: https://gstreamer.freedesktop.org/documentation/installing/on-linux.html?gi-language=c#
Where it says to build the tutorials with:
gcc basic-tutorial-1.c -o basic-tutorial-1 `pkg-config --cflags --libs gstreamer-1.0`
Which, of course, does not work in fish (because backticks). But when converted to $() syntax, it errors with:
gcc: error: unrecognized command-line option ‘-pthread -I/usr/include/gstreamer-1.0 -I/ ....
Because it has interpreted the output of the $() block as a single string -- which makes sense and seems sensible, except that it is blocking this very reasonable (imo) use case, and I'd like to be able to do this comfortably in fish.
Thanks!
string split
, noteval
. – Validityls $(echo '-l -h')
doesn't requireeval
on my config!!? What's your environment? – Pigmentfish
somethingshell
compatible? I think OP could just use fish. – Pigment