If the option has a required argument, it may be written directly after the long option name, separated by `=’, or as the next argument (ie. getopts --help The above command will print the details of the command along with some parameters and options that public class Getoptextends Object This is a Java port of GNU getopt, a class for parsing command line arguments passed to programs. is: no_argument (or 0) if the option does not take an argument; required_argument (or 1) if the option requires an argument; or optional_argument (or 2) if the option takes an optional argument. Option values are the first argument after the string. flag specifies how results are returned for a long option. are specified on the getopts command line, getopts parses them instead. That's the standard convention — some GNU utilities accept options after arguments, but the normal thing is that in somecommand foo -bar qux , -bar is not parsed as an option. Firstly, according to the code getopts argument list (:s:dvu:p:n:), -s, -u, -p, and -n take a mandatory argument. For example, the string 'ht' signifies that the options -h and -t are valid. 유저 모드 에뮬레이션은 하드웨어 디바이스는 에뮬레이션 하지 않고 cpu instruction 과 system call 을 에뮬레이션 합니다. See note. 「If the option has a required argument, it may be written directly after the long option name, separated by '=', or as the next argument (i.e. shift is a shell builtin which moves the positional parameters of the script down a specified number of positions provided to it as a positive number, discarding the related arguments. The getopts function takes three parameters. While the getopt system tool can vary from system to system, bash getopts is defined by the POSIX standard. The first is a specification of which options are valid, listed as a sequence of letters. /usr/lib/getoptcvt reads the shell script in filename , converts it to use getopts instead of getopt , and writes the results on the standard output. Syntax getopts optstring name [args] Options optstring : The option characters to be recognized If a character is followed by a colon, the option is expected to have an argument, which should be separated from it by white space. My understanding is that getopts won't do what you're trying to do.. you can easily use if..then's after the while..loop to determine if the user has entered the required information. So, just add a "f:" to flags list, and use that to set the filename variable inside the getopts loop. getoptがoption argumentを持つoptionを解析すると、 optargにoption argumentへのポインタが設定されます。 optargを参照することでoption argumentを取得できます。 optind optindはgetoptが次に処理するargv配列のindexです。初期値は When getopts obtains an option from the script command line, it stores the index of the next argument to be processed in the shell variable OPTIND. The symbolic constants are macros for the numeric values given in the table. )をコマンドライン引数としてみなして処理します。つまり、'--version'といったものはオプションとして認識しません。 is placed in name, OPTARG is unset, and a diagnostic message is printed. separated by whitespace on the command line). If getopts is silent, then a colon (:) is placed in name and OPTARG The type of argument… The getopt() is one of the built-in C function that are used for taking the command line options. Hi, Does the order of argument and non-argument command line parameters matter to getopts? with a getopts line in my script of getopts p:cs opt a command line of