Shell Summary (0 basic primer)

Source: Internet
Author: User

First, Introduction

The shell is the command-line interpreter that the user interacts with the operating system.

There are many kinds of shells:

bash, csh, sh, ksh 、、、

The command line we saw when we waited for Linux was a bash.

Two, the first script:

[Email protected] script]# vim first.sh
#!/bin/bash
#auther: Xiaofan
#time: 2016.10.4
#井号是注释
echo "Hello word"

Execute script:

Method 1:

[Email protected] script]# bash first.sh
Hello Word

[Email protected] script]# sh first.sh
Hello Word

Method 2:
[Email protected] script]# chmod +x first.sh
[Email protected] script]#./first.sh
Hello Word

To view the script execution process:

[Email protected] script]# sh-x first.sh
+ echo ' Hello word '
Hello Word

Third, variable

There are two main categories of variables:

Local variables: You need to define them yourself.

Environment variables: The system comes with.

Variable definition:

Variable name = variable Value

To invoke a custom variable:

[Email protected] script]# name= "Xiaofan"
[Email protected] script]# echo "My name is $name"
My name is Xiaofan
[Email protected] script]# echo my name is $name
My name is Xiaofan
[Email protected] script]# echo ' My name is $name ' #注意单引号是不会解释变量的
My name is $name

Common system Variables:

[email protected] script]# cat t1.sh
#!/bin/bash
Echo #当前程序名
echo $ #程序的第一个参数
Echo $* #程序的所有参数名
Echo $# #当前程序的参数个数
echo $? #程序执行的返回状态
Echo $PATH #系统环境变量的路径
Echo $PWD #当前目录
Echo $UID #当前用的id
[Email protected] script]# sh t1.sh t1 T2
t1.sh
T1
T1 T2
2
0
/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/root/bin
/script
0

Third, the script output color font:

\033[32m and \033[0m fonts will turn green.

All the fonts below \033[32m and \033[1m will turn green.

Shell Summary (0 basic primer)

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.