For example, if i have a shell program “shell1” and run “./shell1 hello world”, how can I store the hello world in a variable? If I try to use read, it only accepts user input after I run ./shell1 first.
Share
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.
You are referring to parameters being passed to the script.
To capture them use
$1for the first parameter,$2for the second,$3for the third, and so forth. Use"$@"to capture all parameters into a single variable.For example, try adding the following to your script:
Take a look at Advanced Bash-Scripting Guide: Positional Parameters for more information.