Doesn't xargs work, this would be the
'normal' way eg
ls -1 | xargs -I var echo var
compared to
ls -1 | xargs echo
On 16/09/2011 04:18, Jan Kanis wrote:
Hi everyone,
I ran into the following problem: I
want to pass the result of one command
as the parameter of another command.
Normally command substitution is the
way to go but if the output contains
newlines, I want to pass them
verbatim. In all the ways I tried fish
splits the output into multiple
arguments.
My use case:
notify-send "Program crashed!" (grep !
logfile)
Try
count (echo 1\n2\n3) ==> 3
I want some way to make that expand into
count 1\n2\n3
instead of
count 1 2 3
AFAIK fish has no syntax to say "use
the result of this command as a single
argument". Did I miss anything on this?
It's possible to manually use a loop
to stitch the command result back
together again, but the result cannot
be returned from a function, because
then it will be split up again. So
it's hard to abstract such
functionality. I worked around this
using the following function:
function strjoin --description
'\n-safe string join function; output
in $<first arg>'
set -l var $argv[1]
set -l sep $argv[2]
if [ (count $argv) -ge 3 ]
set $var $argv[3]
end
for i in (seq 4 (count $argv))
set $var {$$var}$sep$argv[$i]
end
end
use as:
set -g logentries #make empty
global variable
strjoin logentries \n (grep ! logfile)
notify-send "Program crashed!" $logentries
But this is still ugly, requires
several lines to use instead of a
simple command substitution, and uses
additional global variables with the
risk of variables clashing.
FWIW, bash handles this better, it
allows command substitution in a
double quoted string, resulting in a
single argument. One option for fish
syntax would be to allow
notify-send "Program crashed!" "(grep
! logfile)"
I think that would be the nicest, and
it's analogous to the "$a" syntax for
making an array expand into a single
argument.
So:
- Is there syntax that I missed that
does this?
- If not, do we need any? I think it
is an important feature to be able to
handle special characters in any output
- What kind of syntax would do?
Jan
------------------------------------------------------------------------------
Doing More with Less: The Next Generation Virtual Desktop
What are the key obstacles that have prevented many mid-market businesses
from deploying virtual desktops? How do next-generation virtual desktops
provide companies an easier-to-deploy, easier-to-manage and more affordable
virtual desktop model.http://www.accelacomm.com/jaw/sfnl/114/51426474/
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users
------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users