Bash commands-create a script with multi-parameter

Source: Internet
Author: User

#! /Bin/bash

# Call this script with at least 10 parameters, for example
#./Scriptname 1 2 3 4 5 6 7 8 9 10

Minparams = 10

Echo

Echo "the name of this script is \" $0 \"."
Echo "the name of this script is \" 'basename $0 '\"."

Echo

If [-n "$1"]#-N test string be quoted is not null.
Then
Echo "parameter #1 is $1" # Need quotes to escape #
Fi

If [-n "$2"]
Then
Echo "parameter #2 is $2"
Fi

If [-n "$3"]
Then
Echo "parameter #3 is $3"
Fi

If [-n "$4"]
Then
Echo "parameter #4 is $4"
Fi

If [-n "$5"]
Then
Echo "parameter #5 is $5"
Fi

If [-n "$6"]
Then
Echo "parameter #6 is $6"
Fi

If [-n "$7"]
Then
Echo "parameter #7 is $7"
Fi

If [-n "$8"]
Then
Echo "parameter #8 is $8"
Fi

If [-n "$9"]
Then
Echo "parameter #9 is $9"
Fi

If [-n "$ {10}"]#
Parameters> $9 must be enclosed in {brackets}.
Then
Echo "parameter #10 is ${10 }"
Fi

Echo "-------------------------"
Echo "all the command-line parameters are:" $ *""

If [$ #-lt "$ minparams"]
Then
Echo
Echo "this script needs at least $ minparams command-line arguments! "
Fi

Echo

ARGs =$ ## Number of argS passed.
Lastarg =$ {! ARGs}

Echo "lastarg = $ lastarg"
Echo "lastarg =$ {! #}"

Exit 0

Note that$ #: Number of command-line arguments; $ *: All of the positional parameters and
Must be quoted "".

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.