How to pass a string appended to script?
I want to have a few variables already created in the script, but then be able to append these variable names to the script being run; to run customized commands using a case statement.
Like this: ./script customA ./script customB I have found many tutorials on prompting the user for input, but I need to pass a parameter to my script before it starts, thus running a predefined command inside of the case statement. Thanks! |
Hi! Did you mean like $1, which google shows via a search for:
shell script arguments (or something more obscure/complex)? [quoting issues IF var not 1word] |
Yes, $1 is one way of writing a reference to the first parameter used with the script.
See the special variables $# and ${1}, ${2}, and so on. The ${#} tells you the number of arguments used to launch the script ${1} tells you the first, ${2} tells you the second and so on. If you use braces { } around the variable names, you can go into double-digits like with ${10} and ${11} if you need. The built-in command "shift" will work on $#, too. The manual page for the shell you are using (sh, dash, bash) will have some more details. |
There are also environment variables...
and "include" scripts to set local variables... |
All times are GMT -5. The time now is 08:24 PM. |