Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I3WM installer script issue.
Hey everyone!

I am trying to write a script to install the I3 window manager along with specific software on my machines so I don't have to do everything manually.

I include a --help and a --minimal option that the user can invoke as an argument when running the script.

Here is the script if you'd like to read, it's not that complicated:

The if statements starting at line 127 test if the user has entered either the --help or --minimal option to the script. When I look at the code it seems fine to me (probably cause I'm a noob) but when I invoke either option, the script just executes normally and does not take the option 
into account.

I'm probably missing something or doing something wrong. Any thoughts?
To implement command flags properly in shell scripts, use 'getopt' or 'getopts'.

For simpler scripts, a 'case' can be enough:

case "$*" in
        echo "1"
        echo "2"

This however is quite limited. If you plan to do anything at least
slightly complicated with command flags, use 'getopt' / 'getopts'.

I recommend this video to learn about 'getopts'.

I am not an expert but i guess you should change ${1] by $1

Or maybe in the "main_function" (line 143 to be specific) you should change to this:

user_input_test $1

Yes, cause your arguments are scripts arguments, you need to parse it to your function.

For more details read this:

I hope it helped.
(04-12-2019, 09:49 AM)Tuxinho Wrote: I am not an expert but i guess you should change ${1] by $1

Putting the variable name inside {curly braces} is not just valid bash snytax but also generally seen as preferrable over not doing so.

Forum Jump:

Users browsing this thread: 1 Guest(s)