🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.os.linux.programowanie
3 messages
3 total messages Started by piecia aka dracorp Wed, 16 Mar 2011 10:55
[BASH]Opcjonalne argumenty dla getopts
#72159
Author: piecia aka dracorp
Date: Wed, 16 Mar 2011 10:55
8 lines
1192 bytes
Witam
Czy istnieje jakiś sposób na podanie opcjonalnych argumentów dla getops? 
W manie się nie doszukałem ale może coś przeoczyłem. Dla getopt wystarczy 
podać za literką :: i wówczas argumenty dla tej opcji będą opcjonalne.

-- 
piecia aka dracorp
pisz na: piotr kropka rogoza at wp kropka eu
Re: [BASH]Opcjonalne argumenty dla getopts
#72160
Author: Michal Jaegermann
Date: Thu, 17 Mar 2011 22:50
31 lines
2295 bytes
piecia aka dracorp <imie.nazwisko@wp.eu> wrote:
> Czy istnieje jakiś sposób na podanie opcjonalnych argumentów dla getops? 

O tyle, o ile.

> W manie się nie doszukałem ale może coś przeoczyłem.

'help getops' mówi:

    getopts reports errors in one of two ways.  If the first character
    of OPTSTRING is a colon, getopts uses silent error reporting.  In
    this mode, no error messages are printed.  If an invalid option is
    seen, getopts places the option character found into OPTARG.  If a
    required argument is not found, getopts places a ':' into NAME and
    sets OPTARG to the option character found.
....

> Dla getopt wystarczy 
> podać za literką :: i wówczas argumenty dla tej opcji będą opcjonalne.

Jak się zrobi jak wyżej no to można mieć "opcjonalne" tyle, że całe
"error handling" już należy wtedy do programującego.  Trudno zgadnąć po
co to, ale bym pewnie czegoś takiego unikał.  Patrz także OPTERR.

Taka drobna uwaga: w 'info bash' to figuruje jako
"getopts OPTSTRING NAME [ARGS]" i 'NAME' powyżej referuje do tegoż.
'help getops' zaczyna się od "getopts: getopts optstring name [arg]"
to jest to samo 'NAME'. :-)  Podobnie z 'arg' i 'ARGS' z lepszym
wyjaśnieniem w 'info bash'.

   Michał
Re: [BASH]Opcjonalne argumenty dla getopts
#72161
Author: piecia aka dracorp
Date: Fri, 18 Mar 2011 07:30
11 lines
1175 bytes
Dnia Thu, 17 Mar 2011 22:50:15 +0000, Michal Jaegermann napisał(a):

>    Michał
Dzięki, w zupełności wystarczy.




-- 
piecia aka dracorp
pisz na: piotr kropka rogoza at wp kropka eu
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads