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"
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
- bash变量
- bash变量
- Bash变量
- bash 变量
- bash变量
- BASH变量
- Bash变量--位置参数变量
- Bash中的变量
- BASH中变量转换
- 特殊Bash变量
- bash 变量赋值方式
- bash 变量赋值方式
- bash变量和运算
- bash变量自动拓展
- Bash中的变量
- Bash中的变量
- bash 内置变量
- bash变量(variable)
- 使用hubble.net实施全文搜索笔记
- 你所不知道的事儿--C++中delete指针后最好赋值为NULL
- SCU-4438 Censor(KMP算法)
- Matrix
- android 通过加速度传感器实现手机来电时翻转静音
- bash 变量
- [刷题]算法竞赛入门经典(第2版) 5-3/UVa10935 - Throwing cards away I
- 面试漫谈参考
- 算法导论习题(9)
- 多校10
- java语言的历史
- 用户特征工程 超详细解读
- C++--堆和栈详解
- 开发感想