bash 变量

来源:互联网 发布:海贼王887 知乎 编辑:程序博客网 时间:2024/06/01 23:59
1、自定义变量
set
    查看变量
unset
删除变量


echo $name
变量调用
变量叠加
EX:
aa=123
aa="$aa"456
aa=${aa}456
2、环境变量
export 变量名=变量值  bash下开bash
env 查询变量
unset 。。
PATH="$PATH":地址

PS1='[\u@\w \t]\$'


3、位置参数变量
$n n:数字
EX: echo $0 echo $1
#!/bin/bash
num1=$1
num2=$2
sum=$(($num1 + $num2))


echo $sum




$* 参数所有内容(参数是一个整体)
$@ 参数所有内容(不过是参数是独立的)
$# 参数个数




4、预定义变量


$? 接受判断上一条命令的返回状态
$$ 当前进程号PID
$! 最后一个进程PID
EX:
#!/bin/bash
#author
echo "the current process is $$"
find /root -name hello.sh &&是将挂到后台
echo "the last one process is $!"
5.接受键盘参数
read 
-p 提示信息
-t 秒数
-n 字符数
-s 隐藏输入数据


EX:
#!/bin/bash
#
read -t 30 -p "please input your name :"name
echo "Name is $name"

read -s -t 30 "Please input your age:"age
echo "Age is $age"
echo -e "\n"


#!/bin/bash
read -n 1 -t 30 -p "Plaese select your gender[M/F]:"gender
echo -e "\n"
echo "Sex is $gender"

































0 0
原创粉丝点击