Is there a way to implement/use lambda functions in bash? I'm thinking of something like:
$ someCommand | xargs -L1 (lambda function)
Is there a way to implement/use lambda functions in bash? I'm thinking of something like:
$ someCommand | xargs -L1 (lambda function)
I don't know of a way to do this, however you may be able to accomplish what you're trying to do using:
somecommand | while read -r; do echo "Something with $REPLY"; done
This will also be faster, as you won't be creating a new process for each line of text.
[EDIT 2009-07-09] I've made two changes:
-r
to disable backslash processing -- this means that backslashes in the input will be passed through unchanged.X
) as a parameter to read
, we let read
assign to its default variable, REPLY
. This has the pleasant side-effect of preserving leading and trailing spaces, which are stripped otherwise (even though internal spaces are preserved).From my observations, together these changes preserve everything except literal NUL (ASCII 0) characters on each input line.