getopt '::' in --longoptions, seems to default to "no argument" [solved]

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
s243a
Posts: 501
Joined: Mon Dec 09, 2019 7:29 pm
Has thanked: 90 times
Been thanked: 37 times

getopt '::' in --longoptions, seems to default to "no argument" [solved]

Post by s243a »

This stumped me for a little bit (maybe 30m to an hour) but I couldn't figure out why getopt was rearranging the input argument that followed a long option with "::". For instance:

Code: Select all

getopt -o c:,e:,n: --long chroot-cmd::,chroot-command::,cmd::,::command::,no-exit::,source-subdir:,dest-subdir: -- --source-subdir /cont/01firstrib_lgo_rootfs --chroot-command /bin/sh

becomes:

Code: Select all

declare -a 'options= --source-subdir '\''/cont/01firstrib_lgo_rootfs'\'' --chroot-command '\'''\'' -- '\''/bin/sh'\'''

Notice that the argument for --chroot-command gets moved after the "--". I think the solution is to use an equal sign "=" rather than a space " " to separate the option and its argument.

Edit: That seemed to work. I wonder if this behavior is version dependent.

Post Reply

Return to “Programming”