Is there a way to implement/use lambda functions in bash? I’m thinking of something like:
$ someCommand | xargs -L1 (lambda function)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t know of a way to do this, however you may be able to accomplish what you’re trying to do using:
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:
-rto disable backslash processing — this means that backslashes in the input will be passed through unchanged.X) as a parameter toread, we letreadassign 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.
[EDIT 26/7/2016]
According to commenter Evi1M4chine, setting
$IFSto the empty string before runningread X(e.g., with the commandIFS='' read X) should also preserve spaces at the beginning and end when storing the result into$X, meaning you aren’t forced to use$REPLY.