shell 变量
#!/bin/bash
A=123
echo $A
#!/bin/bash
name=张三
echo "This is my name:$name"
执行结果
This is my name:张三
获取环境变量
#!/bin/bash
echo $UID
echo $PWD
结果
0
/home/shell
UID为0表示root用户!
#!/bin/bash
echo $UID
echo $PWD
echo "###################"
echo $0
echo $1
输出结果:
# /bin/bash var.sh hello
0
/home/shell
###################
var.sh
hello
其中$0 表示文件本身 $1 表示第一个参数
#!/bin/bash
#变量的使用
echo "###################"
echo "The \$? is $?"
echo "The \$* is $*"
echo "The \$# is $#"
echo "The \$1 is $1"
echo "The \$2 is $2"
# /bin/bash var.sh hello world
###################
The $? is 0
The $* is hello world
The $# is 2
The $1 is hello
The $2 is world
#!/bin/bash
#变量的使用
echo -e "\033[32m###################\033[0m"
echo "The \$? is $?"
echo "The \$* is $*"
echo "The \$# is $#"
echo "The \$1 is $1"
echo "The \$2 is $2"