Shell script Programming {1} per day

Source: Internet
Author: User
Tags ibase

Variable definition and use

$var =value------don't add spaces around the equals sign

$echo $var--$var to reference a variable

$age = 20--Variable assignment

$echo "She is $age"--reference variable in string, ${age}, can distinguish variable boundary

Environment variables

$echo ${path}--like the PATH variable under win

$PATH = "$PATH:/home/user/jdk1.6.1/bin"

$export PATH-A script execution that can specify environment variables, modify or delete environment variables, only valid for this script execution, not permanently valid

Other uses of variables

$var =123456

$echo ${#var}--Get the length of the variable

$echo $SHELL--Displays the current SHELL version information

A simple if operation

if [$UID-ne 0] Then echo "not Root." Else echo "Root User." fi

Note: If the Terminator is fi, this notation is more common in Linux. -ne,-eq,-gt,-lt is used to compare integers. ==,!= is used to compare characters. There is a space between if and [. $UID is the ID of the current logged-on user.

A simple operation

Num1=1;

num2=2;

Let result=num1+num2;

Echo $result

Note: Using let for simple operations, floating-point numbers are not supported.

Mathematical Operations advanced Tools BC

echo "4*0.11" | BC-Output:. 44. | For the pipe symbol, the previous processing output as the next input.

No=8

echo "obase=2; $no" | BC-output Result: 1000. Obase:out-base, Output binary.

no=1000

echo "obase=10;ibase=2; $no" | BC-Output: 8.ibase:in-base, input binary.

Note: Using BC parameters, we can specify the binary, complete the conversion between the binary value.

echo "sqrt (100)" | BC--Open square

echo "10^2" | BC-the second party

Shell script Programming {1} per day

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.