个别应用#!/bin/bash来解析shell语法,当然还有zsh, ksh等,但个别用的最多的就是bash
一、变量
-e
参数:解析echo中的特殊字符,如换行:echo -e "Hello \nWorld"
1.1、 单引号 '
如果变量被蕴含在单引号外面,那么变量不会被解析。$符号会原样输入。
1.2、 双引号 "
双引号会疏忽大多数特殊字符,然而不包含
$
、反引号
、\
所以不疏忽$
意味着Shell在双引号外部能够进行变量名替换
1.3、 反引号 `
反引号要求Shell执行被它括起来的内容
1.4、 read
申请输出,同时给多个变量赋值
- 能够应用
read
命令一次性给多个变量赋值 read
命令每个单词之间应用空格离开-
-p
参数: 提示信息:prompt
read -p 'Please enter a Fruit and Animal:' fruit animal echo "fruit is $fruit, animal is $animal"
-
-n
参数: 限度字符数n
是number
的首字母
用-n
能够限度用户输出的字符串的最大长度(字符数)read -p 'Please enter your name(5 characters max): ' -n 5 name echo -e "\nHello $name !"
-
-t
:限度输出工夫t
是time
的首字母-t
参数能够限定用户的输出工夫(以秒为单位)
超过这个工夫,就不读取输出了#!/bin/bash read -p 'Please enter the name (you have 5 seconds): ' -t 5 name echo -e "\nyour name is $name.... !"
-
-s
:暗藏输出内容-s
是secret
的首字母#!/bin/bash read -p 'Please enter the password : ' -s password echo -e "\npassword is $password.... !"
1.5、
发表回复