zparseopts - If no argument is given to compulsory option, it takes next option as the argument
I am using zsh 5.4.2. The function that is causing issue is:
Code:
function zp () { Code:
$ zp --show --watch "Watching" Why is --watch taking --show as an argument instead of throwing an error. |
zparseopts - How to make an option (not argument of the option) mandatory
In The example bellow:
Code:
function zp () { Code:
$ zp --walk "Walking" How can I make the option mandatory so that I must pass --walk to zp else it will throw an error. |
zparseopts - How to pass multiple argument to an option
In The example bellow:
Code:
function zp () { Code:
$ zp --walk Walking --walk Run It looks weird if we do something like: Code:
command -f "file1 file2 file3" Something like: Code:
command -f file1 file2 file3 |
you need to check getopt (and/or getopts) which is used to handle this.
Otherwise you need to check $# (and additionally $1, $2 ....) see for example: https://dustymabe.com/2013/05/17/eas...a-bash-script/ this is a much better example: https://stackoverflow.com/questions/...d-line-options |
duplicate of https://www.linuxquestions.org/quest...ry-4175677148/
please open only one thread about argument parsing |
duplicate of https://www.linuxquestions.org/quest...ry-4175677148/
please open only one thread about argument parsing |
What might be the solution with $# & $1, $2 ....?
|
as far as I see your problem is relatively complex, you need to look for a ready-made solution (like getopt) instead of re-implementing it again.
|
These are different questions regarding zparseopts. If I open one question with all these queries then no one will even touch these questions because it will be too complicated.
|
These are different questions regarding zparseopts. If I open one question with all these queries then no one will even touch these questions because it will be too complicated.
|
I have checked getopt, getopts & zparseopts. All my problems are solved with zparseopts except these three issues.
Moreover, I have to rewrite a lot of stuff if I try to replace zparseopts now. |
The solution that I found is:
Code:
function zp () { |
I actually realized that it looks perfectly natural to have -f "file1 file2 file3" and very weird to have -f file1 file2 file3. So, I am quiting the pursuit to the answer of this question.
|
All times are GMT -5. The time now is 06:25 AM. |