, it will be impossible.
To solve these problems. Bash contains a built-in command getopts, which can extract and check the switch without messing up the positioning parameters. Unexpected parameters or missing parameters will be re-identified and reported.
To use getopts, you need to take some preparation work. First, you must set it to a string to use the s
Write shell scripts Common sh test.shThe notation of-M 2-d 3Case script:#!/bin/bashwhile getopts ": a:b:c:" Arg #选项后面的冒号表示该选项需要参数doecho "arg": $arg case $arg in a) echo "a ' s ARG: $OPTARG---$OPTIND "#参数存在 $OPTARG ;; b) echo "B ' s arg: $OPTARG--- $OPTIND" ;; c) echo "C ' s ARG: $OPTARG---$OPTIND";; ?) #当有不认识的选项的时候arg为?
Getopts is a built-in command of the shell, typically used to handle shell command-line options, but cannot handle long options (such as--prefix=/home, etc.) directly.Getopts has 2 parameters, the first parameter is a string, including the character and ":", each character is a valid option, if the character is followed by ":", indicating that the character has its own parameters. The second parameter is used to store the acquired options.The shell pr
parameters, you will need to reset the Optind to 1 yourself. For more details, please refer to the Bash manual or information page.Back to top of pageParameter extensionNow that you've learned how to pass parameters to a function or script and how to identify options, start working with options and parameters. It should be a good thing if you know what parameters are left after processing the options. Next you may need to verify the parameter values
When writing a shell program, you often need to handle command-line arguments, and this article describes the command-line approach under bash.Options and Parameters:Like the following command line:
Copy Code code as follows:
./test.sh-f Config.conf-v--prefix=/home
-F is an option, it requires a parameter, that is, config.conf,-V is also an option, but it does not require parameters.
--prefix We call it a long option, the option itself is more than one character, it also requir
values of the shell options and positional parameters.5. Position variablesCalling parameters passed to the script from the command line in the script$, $ ... : corresponding to the command line of the 1th, 2nd ... A parameter$: Command itself$*: All parameters passed to the script, all parameters as a whole[Email protected]: All parameters passed to the script, each parameter is independent$#: Number of arguments passed in a scriptShift [n]: Kicks out n parameters6. Logic operation:: With|| :
This article is one of the book notes in Chapter 6 "learning the bash shell" 3rd edition "command-line options and typed varilables, but we will not limit this article.
In Linux commands, parameters such as [-Option] are often included. There may be 0 or more options in the command line. We learned the location parameters before, including $1, $2, $3 ..., $ *, $ #, See Linux bash shell Learning (7): shell p
Tags: mil tle ons generated break getopt mkdir tool command line Options0. IntroductionWhen writing a program, you often have to handle command-line arguments, and this article describes the command-line processing under bash.Options and Parameters:As the next command line:./test.sh-f Config.conf-v--prefix=/homeWe call-f as the option, it requires a parameter, namely config.conf,-V is also an option, but it does not require parameters.--prefix We call it a long option, that is, the option itself
0. IntroductionWhen writing a program, you often have to handle command-line arguments, and this article describes the command-line processing under bash.Options and Parameters:As the next command line:./test.sh-f Config.conf-v--prefix=/homeWe call the-f option, which requires a parameter, i.e. config.conf;-V is also an option, but it does not require parameters;--prefix We call it a long option, that is, the option itself is more than one character, it also needs a parameter, with an equal sign
Original URL: http://www.cnblogs.com/FrankTan/archive/2010/03/01/1634516.html0. IntroductionWhen writing a program, you often have to handle command-line arguments, and this article describes the command-line processing under bash.Options and Parameters:As the next command line:./test.sh-f Config.conf-v--prefix=/homeWe call-f as the option, it requires a parameter, namely config.conf,-V is also an option, but it does not require parameters.--prefix We call it a long option, that is, the option i
Daniel RobbinsPresident and CEO, Gentoo Technologies, Inc.March 2000
By learning how to program using the bash scripting language, you can make the daily interaction of Linux more interesting and productive. You can also use the familiar and favorite standard UNIX concepts (such as pipelines and redirection ). In this three-part series, Daniel Robbins provides an example of how to program using bash. He wil
((i=0; i For ((j= $i; jIf [${array[$i]}-gt ${array[$j]}]; Thentemp=${array[$i]}array[$i]=${array[$j]}array[$j]= $TEMPFiDoneDoneEcho-n "ARRAY Sorted is:"For ((I=0;i echo-n "${array[$i]}"DoneEcho8. Custom generates the specified number of array elements, and the elements within the array cannot be the same and display them, as in the following script:#!/bin/bash#Read-p "The element number[1-50]:" ElenumDeclare-a ARRAYfunction Comele {Local IFor I in '
$ echo the last argument is$$#The last argument is $4$ eval echo the last argument is$$#The last argument is D[Email protected]:~$ set-x//Open bash shell debug function[Email protected]:~$ eval echo the last argument is $$#+ eval echo the last argument is ' $4 '+ + echo the last argument is DThe last argument is DIv. Exit commandThe exit command ends the script to return to the command line.The exit command can take a return value parameter, 0 means a
Linux Bash severe vulnerability emergency repair solution, bash severe vulnerability
Recommendation: 10-year technical masterpiece: High-Performance Linux Server build Practice II is released across the network, with a trial reading chapter and full-book instance source code download!
Today, a Bash security vulnerability has been detected.
]; then pwd fi echo "" done file descriptor in BASH, execute operations related to the file descriptor using the exec command: exec n> outfile open outfile as the output file, assign the file descriptor nexec n BASH built-in commands have been mentioned earlier. here is a summary and supplement.: Returns 0 or true (empty internal command ). use shell scripts as part of the current process to execute bg pending task break jump out of loop cd cha
6.3 Interactive Shell
* What is an interactive shell? What makes a Shel interactive.* Is it an interactive shell? How to determine whether a shell is interactive.* What are the differences between Interactive Shell and interactive shell?
6.3.1 what is an interactive shell?Interactive Shell has no non-option parameters except-s at startup, does not specify the-C option, and the input and error outputs are all connected to the terminal (determined by isatty (3 ), or use the-I option to start the
Bash introduction, bash Vulnerability
Bash is not just a command parsing program. It has a programming language, which allows you to write shell scripts to complete a variety of tasks that cannot be completed by using ready-made commands, bash scripts can use if-then-elif-else-fi statements, for statements, while stat
Linux basics-Bash command priority, linux-bash priority
1. Bash Introduction
The command interpreter, also known as the Bourne Again Shell, originated from the shell. Shell, commonly known as shell, refers to a command parser in a UNIX system. It is mainly used for user-system interaction. There are many types of shells on UNIX systems. The first shell, namely, t
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.