I have a script using a pretty long pipe quite a lot of times. The middle of each pipe is the same command chain. Only the beginning and the end defers all the time it is used.
Different-command-1 |
command A |
command B |
command C |
diff-cmd-2
is there a way to call this commands as a function within the pipe? Like:
same-commands() {
command A |
command B |
command C
}
Different-command-1 |
same-commands |
diff-cmd-2
Different-command-3 |
same-commands |
diff-cmd-4
this in my case would save quite a lot of lines in my script, but I can not quite figure out how this could work.
func() { foo | bar; }
and then usefunc
in place offoo | bar
– ilkkachu Dec 07 '17 at 19:31syntax error near unexpected token ('
maybe I should come up with a real MWE that could run... – nath Dec 07 '17 at 19:50