I want to add another possibility to the script kplatforms.sh as an optionnal argument. The way it is coded actually is that the last argument is optionnal. So I would like something like an usual Linux command.

Example:
./kplatforms.sh -d distribution -n platform-name [-s platform-state] [-x]
instead of:
./kplatforms.sh distribution platform-name [platform-state]

See also http://drupal.org/node/1323836

CommentFileSizeAuthor
#2 test.sh_.txt619 bytesmvc

Comments

j0nathan’s picture

Priority: Normal » Major

Increasing priority because #1488566: htpasswd and htaccess in kplatforms.sh depends on this.

mvc’s picture

StatusFileSize
new619 bytes

This is much easier if the user has to write the arguments in the same order, and they can only give the fourth argument when the third one is also present. Then you don't need to write -d or -n. So the command usage would be written:

kplatforms.sh distribution platform-name [platform-state [other argument]]

I have attached an example showing how to do that.

If you really want to allow optional arguments in any order, you will need to use the bash getopts function:
http://wiki.bash-hackers.org/howto/getopts_tutorial
Or use someone else's function to parse these:
https://www.linuxquestions.org/questions/programming-9/bash-script-parsi...

j0nathan’s picture

Assigned: Unassigned » j0nathan

Thank you very much mvc, I'll start with this example and the links.

j0nathan’s picture

Status: Active » Fixed

This is committed in 5.x-1.x, 6.x-1.x and 7.x-1.x.
kplatforms.sh and README.txt updated.
Documentation updated at http://drupal.org/node/1323836

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

j0nathan’s picture

Component: Code » Scripts

  • Commit a7a45c0 on 7.x-1.x, 7.x-4.x, 7.x-5.x, 7.x-6.x, stubs, 8.x-1.x, 8.x-2.x, lock by j0nathan:
    #1487262 arguments of the script kplatforms.sh with getopts in the...
  • Commit c410d80 on 7.x-1.x, 7.x-4.x, 7.x-5.x, 7.x-6.x, stubs, 8.x-1.x, 8.x-2.x, lock by j0nathan:
    #1487262 arguments of the script kplatforms.sh using getopts