Chinaunix

标题: shell 如何实现像mysql 命令一样 -p 密码 -P 端口 [打印本页]

作者: topstargogo    时间: 2016-09-18 14:32
标题: shell 如何实现像mysql 命令一样 -p 密码 -P 端口
shell 如何实现像mysql 命令一样 -p 密码 -P 端口

就是自动判断传入的参数。然后变量赋值

作者: jason680    时间: 2016-09-18 15:45
回复 1# topstargogo

$ man getopt

GETOPT(1)                        User Commands                       GETOPT(1)

NAME
       getopt - parse command options (enhanced)

SYNOPSIS
       getopt optstring parameters
       getopt [options] [--] optstring parameters
       getopt [options] -o|--options optstring [options] [--] parameters

DESCRIPTION
       getopt  is  used  to break up (parse) options in command lines for easy
       parsing by shell procedures, and to check for legal options.   It  uses
       the GNU getopt(3) routines to do this.

       ...


作者: moperyblue    时间: 2016-09-18 17:19

getopts

http://bbs.chinaunix.net/thread-1823335-1-1.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2