The standard way to pass parameters to a script is not with read
(which actively waits for input from stdin), but just to call your script with the parameters on the same line:
./my_script.sh param1 param2
Then inside the script, you can access these parameters using $1
, $2
, etc. Example (note also the first line - this describes what shell should be used to run the script, and should be a valid path - ie /bin/bash
, not backslashes):
#!/bin/bash
echo "First: $1 Second: $2"
Then call the script:
$ ./my_script.sh Hello There
First: Hello Second: There