Easy Tutorial
❮ Mysql Stored Procedure Android Tutorial Service 3 ❯

Process Substitution in Shell

Category Programming Techniques

Both bash and zsh support Process Substitution.

The syntax is:

<(command) or >(command)

For example:

$ cat <(ls)       # Treat <(ls) as a temporary file with the content of ls, and cat this temporary file

$ ls > >(cat)      # Treat >(cat) as a temporary file, redirect the output of ls to this file, and finally cat this file

Using Process Substitution to redirect stdout and stderr separately:

$ some_command > >(/bin/cmd_for_stdout) 2> >(/bin/cmd_for_stderr)

For more examples, refer to:

# Use temporary files to extract fields from one file and recombine them into another file
$ cut -f1 fileone >t1
$ cut -f5 filetone >t5
$ paste t1 t5

# Use Process Substitution to accomplish this task without temporary files
$ paste -d: <(cut -d: -f1 /etc/passwd) <(cut -d: -f5 /etc/passwd)

# Process Substitution supports nesting
$ sort <(egrep -v '^#' <(paste -d: <(cut -d: -f5 /etc/passwd)  <(cut -d: -f1 /etc/passwd) ) )

>

Original URL: http://hongjiang.info/shell-process-substitution/

** Click to Share Notes

Cancel

-

-

-

❮ Mysql Stored Procedure Android Tutorial Service 3 ❯