Quantcast
Channel: Active questions tagged fish - Stack Overflow
Viewing all articles
Browse latest Browse all 125

Fish command substitution for arguments -- eval safe?

$
0
0

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:

  1. Is using eval in this way actually going to do what I want consistently?
  2. 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!


Viewing all articles
Browse latest Browse all 125

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>