Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I3WM installer script issue.
#1
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: https://pastebin.com/k0Kmxt4S

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?
Reply
#2
To implement command flags properly in shell scripts, use 'getopt' or 'getopts'.

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

Code:
case "$*" in
    *--opt1*)
        echo "1"
        ;;
    *--opt2*)
        echo "2"
        ;;
esac

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'.
Reply
#3
Hello,

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:

Code:
user_input_test $1


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

For more details read this: http://linuxcommand.org/lc3_wss0120.php

I hope it helped.
Reply
#4
(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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)