Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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]
Last edited by Jjanel; 07-02-2016 at 03:34 AM.
Reason: my 1st use of "pretty" msg formatting! Cool ;-)
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.