When the shell script executes, passes parameters to the script

Source: Internet
Author: User

Shell scripts can also receive script parameters, like commands and applications, as they are executed .

An application example:

VI addhead.sh:

Suaddhead ns=591 <$1 |sushw key=dt a=20000|sushw key=fldr,cdp a=1,1 b=0,1 c=1,0 j=1301,1301> $

Perform:

./addhead.sh Rtm_step10_lap.dat rtm_step10_lap.su (where rtm_step10_lap.dat is input data, input to $ $, output: rtm_step10_lap.su)

The tutorials are as follows:

You can use a system-defined positional variable, which is a special type of variable, and you can use the 9 variable to $9 when referencing a script parameter.

Example: Cat example1.sh

#!/bin/bash

#Demonstrate the use of positive variables.

echo "The first parameter:" $

echo "The second parameter:" $

echo "The third parameter:" $

echo "The fourth parameter:" $4

In the above script, the 1th 2 3 4 parameters that were passed to the script file are captured and output by using the $ $ $ $4.

Perform:

#为脚本文件添加可执行权限

chmod u+x example1.sh

#./example1.sh one three four

The first Parameter:one

The second Parameter:two

The three Parameter:three

The fourth Parameter:four

Example 2:example2.sh

Echo ' $ ' = ' $ ' $ ' = ' $ ' $ ' "=" $ $

echo ' $4 ' = ' $4 ' "=" $ $6 ' "=" $6

echo ' $7 ' = "$7 ' $8 '" = "$8 ' $9 '" = "$9

Run:

./example2.sh a b c d e F g h i

Get:

$ = A $ = b $ = c

$4 = d = $ = e $6 = f

$7 = g $8 = h $9 = i

When the shell script executes, passes parameters to the 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.