Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fish shell input redirection from subshell output

When I want to run Wireshark locally to display a packet capture running on another machine, this works on bash, using input redirection from the output of a subshell:

wireshark -k -i <(ssh user@machine "sudo dumpcap -P -w - -f '<filter>' -i eth0")

From what I could find, the syntax for similar behavior on the fish shell is the same but when I run that command on fish, I get the Wireshark output on the terminal but can't see the Wireshark window.

Is there something I'm missing?

like image 838
fabiomargarido Avatar asked Jun 10 '16 16:06

fabiomargarido


People also ask

Is shell capable of input output redirection?

In a shell the user can run programs and also redirect the input to come from a file and output to come from a file.

What is meant by redirecting input output?

On a command line, redirection is the process of using the input/output of a file or command to use it as an input for another file. It is similar but different from pipes, as it allows reading/writing from files instead of only commands.

What is redirection shell?

Before a command is executed, its input and output may be redirected using a special notation interpreted by the shell. Redirection allows commands' file handles to be duplicated, opened, closed, made to refer to different files, and can change the files the command reads from and writes to.

What is input output redirection in UNIX?

Input RedirectionJust as the output of a command can be redirected to a file, so can the input of a command be redirected from a file. As the greater-than character > is used for output redirection, the less-than character < is used to redirect the input of a command.


2 Answers

What you're using there in bash is process substitution (the <() syntax). It is a bash specific syntax (although zsh adopted this same syntax along with its own =()).

fish does have process substitution under a different syntax ((process | psub)). For example:

wireshark -k -i (ssh user@machine "sudo dumpcap -P -w - -f '<filter>' -i eth0" | psub)

bash        | equivalent in fish
----------- | ------------------
cat <(ls)   | cat (ls|psub)
ls > >(cat) | N/A (need to find a way to use a pipe, e.g. ls|cat)
like image 142
grochmal Avatar answered Oct 18 '22 08:10

grochmal


The fish equivalent of <() isn't well suited to this use case. Is there some reason you can't use this simpler and more portable formulation?

ssh user@machine "sudo dumpcap -P -w - -f '<filter>' -i eth0" | wireshark -k -i -
like image 26
Kurtis Rader Avatar answered Oct 18 '22 08:10

Kurtis Rader