você está aqui: Home → Colunistas → Cantinho do Shell
Por Marcelo Beckmann
Data de Publicação: 24 de Setembro de 2007
Uma boa forma de implementar tratamento de opções fornecidas na linha de
comando em shell script é usando getopts
:
while getopts 'vadhm:z:' opcao do case ${opcao} in v) VERBOSE="-v" ;; a) WHATBAK="all" ;; d) WHATBAK="dados" ;; m) WHATBAK="mysql" DBTARGET=${OPTARG} ;; z) WHATBAK="zona" ZNTARGET=${OPTARG} ;; h) usage ;; ?) echo "errou" usage ;; esac done
Na linha:
while getopts 'vadhm:z:' opcao
temos as opções que serão aceitas. Opções seguidas de :
requerem argumento
adicional (obtido via ${OPTARG}
). E o ?
trata os argumentos inválidos.
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Comentários