I want to write a function for when I have something like the following
echo 1 2 3|pick
Pick will then take the arguments and I will do something with them.
How do I do this?
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.
pick() { read -r arg1 arg2 remainder echo first arg is $arg1 echo The remaining args are $remainder }–EDIT (response to question in comment)
One way to loop through the arguments:
pick() { read args; set $args; while test $# -ne 0; do echo $1 shift done }On each iteration of the loop, $1 refers to an argument.