Shell Small Script

Source: Internet
Author: User

1#! /bin/Bash2 3j=04  forIinch "[email protected]"5  Do6j=$ (($j +1)) #累加计算7     Echo-E"$j \c"8 Echo$i9  DoneTen  One  A  while[[ $1= -* ]]; Do#匹配-back with any value -    Case$1 inch --D) debug=1 ;; the   Esac -   Shift -  Done -action=$1 + Shift    

[Email protected]: List of parameters themselves, excluding the command itself
$*: Same as [email protected], but "$*" and "[email protected]" (quoted) and different, "$*" interprets all the parameters as a string, and "[email protected]" is a parameter array

Excerpt one: https://blog.linuxeye.com/389.html

1!/bin/Bash2 3#-o represents a short option, two colons indicates that the option has an optional parameter, the optional parameter must be close to the option4#如-carg and not be-C Arg5#--long indicates the length option6#"[email protected]"It 's explained above.7# -N: Information on Error8# --: To give an example of a better understanding:9#我们要创建一个名字为"- F"directory What will you do? Ten#mkdir-F #不成功, because-f is parsed by mkdir as an option, you can use One#mkdir---F so-F will not be used as an option.  A  -Temp= 'getopt-O Ab:c::--LongA-Long, B-Long:, C-Long::  --N'Example.bash'--"[email protected]"` the  - if[ $? !=0] ; Then Echo "terminating ...">&2; Exit1;fi -  -# Note The quotes around ' $TEMP': They is essential! +#set rearrange the order of the parameters, that is, change the1,$2... $n values that have been rearranged in getopt -Eval Set--"$TEMP" +  A #经过getopt的处理, the specific options are processed below.  at  -  while true; Do -          Case " $" inch --a|--a-Long)Echo "Option a";Shift ;; --b|--b-Long)Echo "Option B, argument \ ' $ '";Shift 2 ;; --c|--c-Long) in# C has an optional argument. As we areinchquoted mode, -# an empty parameter would be generatedifIts optional to # argument is not found. +                          Case " $" inch -                                 "")Echo "Option C, no argument";Shift 2 ;; the*)Echo "Option C, argument \ ' $ '";Shift 2 ;; *                         Esac ;; $--)Shift;Panax Notoginseng*)Echo "Internal error!"; Exit1 ;; -         Esac the  Done + Echo "Remaining arguments:" A  forArg Do the    Echo ' -' "\ ' $arg '" ; +  Done

Shell Small Script

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.