Linux Advanced Bash Programming quad (built-in variable)

Source: Internet
Author: User

A: Basic review

1: File Empty

[Email protected] test]$ >log.txt

2: Normal and Error redirect output

Normal and error append output to same place

[Email protected] test]$ ifconfig &>>log.1

Normal output redirect
[Email protected] test]$ ifconfig >log

Error output redirection
[Email protected] test]$ ifconfig 2>log.2
3: Command execution control

Sleep for 1 seconds

[[email protected] test]$ sleep 1
4:bash Script Start

The bash script must start with this, declaring the command interpreter path

#!/bin/bash
5: User interaction, read user input information and save to variable

Syntax: Read variable 1 variable 2

[[Email protected] bash] $vi read.sh

!#/bin/bash

Echo-n "Please input your name:"

Read name

echo "Your name is: $name"

[[Email protected] bash] $bash read.sh

[[email protected] bash] $please input your name: Jackchen

Your name Is:jackchen

Two: Built-in variable use

Built-in variables: The system is already existing variables, can be used directly. When executing a script, it can be passed inside the script with parameters.

Built-in variables are: $ The script itself

$ .... Parameters

$# a total of several parameters

Exercise 1: inside.sh script as follows, carry 3 parameters 1, 2, 3, print $0,$1,$2,$ #的值

650) this.width=650; "Title=" inside. JPG "src=" http://s1.51cto.com/wyfs02/M01/7E/72/wKiom1b_wmWzf0BGAACeTiIIwsQ155.jpg "alt=" wkiom1b_ Wmwzf0bgaacetiiiwsq155.jpg "/>

Exercise 2: Write a bash script that implements two numbers of additions? Write a calculator?

Write a bash script

[[Email protected] bash] $vi add.sh

#!/bin/bash

Echo $[$1+$2]

[[Email protected] bash] $bash add.sh 3 2

5

Write a calculator

[[Email protected] bash] $vi calc.sh

#!/bin/bash

echo "$" |BC

[[Email protected] bash] $bash calc.sh 2+3*5-6/2

14

This article is from the "Reminder Flower Rain" blog, please make sure to keep this source http://chenwen.blog.51cto.com/771416/1759626

Linux Advanced Bash Programming quad (built-in variable)

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.