Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
Doing "--host=localhost" is unnecessary unless you've got multiple requirements for this script so that it can take in options other than the hostname.
You can just do: myscript.sh localhost
Anything passed at the command line becomes a positional variable starting at 1. So the above is sending a variable called $1 into your script.
Since positional parameters can actually be changed depending on what you are doing the first thing you'd want to do in the script is store what was passed in into another variable that doesn't change:
From then on you could get "localhost" by referencing $HOST.
You can do more than one variable the way I wrote it. The second one would be $2, the third would be $3 etc...
Creating options flags would be something you'd do if you want to have different choices each time. (e.g. --host to specify host or --user to specify user and invocations where you intend to sometimes specify ONLY the user or ONLY the host. If you're specifying both user and host every time then doing it without the --host and --user would be the way to go).