passing on command line options in bash
Posted
by
bryan
on Super User
See other posts from Super User
or by bryan
Published on 2011-06-06T16:33:47Z
Indexed on
2013/10/29
22:01 UTC
Read the original article
Hit count: 381
I have a question. I have a script, a kind of long script written in bash aprox. 370 lines. That has several functions and in those functions the user has to enter information which is then stored in files. ( This is suppose to represent a MySQL database, with the functions INSERT, UPDATE, SELECT, SELECT where x=y.) I created this myself in bash, now the only thing that rests me is that I need to be able to pass arguments on the command line to the script, that will do the same as the script does. I know that bash has positional parameters such as
$1
$2
$3
$*
$@
$0 ( refers to the name of the script)
etc. I know how I can use these parameters in a simple if function. This is not enough for my script. I basicly need to do the same thing that the script does, but then from the command line. I have been struggling with this for a couple of days now and I cannot think of a way to get it to work. Maybe someone here can help me with this?
If you want to have the script. That can be possible, but I don't think I can paste it in here...
EDIT: Link to script, http://pastebin.com/Hd5VsDv2
Note, I am a beginner in bash scripting.
EDIT: This is in reply to Answer 1. As I said I hope I can just replace the if [ "$1" = "one" ] ; then echo "found one"
to if [ "$1" = "one" ] ; then echo SELECT
where SELECT is the function I previously had in my script(above)
http://pastebin.com/VFMkBL6g LINK to testing script
© Super User or respective owner