shell
#!/bin/bash
#显示便量 read 命令从标准输入中读取一行,并把输入行的每个字段的值指定给 shell 变量
read name
echo "$name it is a test"
echo -e "ok! \n" #-e开启转义
echo "it is a test"
echo -e "ok! \c" # -e 开启转义 \c 不换行
echo "it is a test"
echo "it is a test" > myfile
num1=100
num2=100
if test $[num1] -eq $[num2]
then
echo '两个数相等!'
else
echo '两个数不相等!'
fi
your_name="qinjx"
echo $your_name
echo ${your_name}
your_name="runbook"
greeting="hello, """
str="hello,i know you are \"$your_name\"! \n"
echo -e $str
your_name="runbook"
greeting="hello, "$your_name" !"
greeting_1="hello,${your_name} !"
echo $greeting $greeting_1
string="abcd"
echo ${#string}
string="runbook"
echo ${string:1:4}
array_name=(value0 value1 value2 value3)
echo ${array_name[@]}
length=${#array_name[@]}
echo "-- \$* 演示 ---"
for i in ""$*; do
echo $i
done
my_array=(A B "C" D)
echo "第一个元素:${my_array[0]}"
echo "第二个元素:${my_array[1]}"
echo "第三个元素:${my_array[2]}"
echo "第四个元素:${my_array[3]}"
my_array[0]=A
my_array[1]=B
my_array[2]=C
my_array[3]=D
echo "数组的元素为:${my_array[*]}"
echo "数组的元素为:${my_array[@]}"
my_array[0]=A
my_array[1]=B
my_array[2]=C
my_array[3]=D
echo "数组的个数为:${#my_array[*]}"
echo "数组的格式为: ${#my_array[*]}"
val=`expr 2 + 2`
echo "两数之和为:$val"
a=10
b=20
val=`expr $a + $b`
echo "a + b : $val"
a=10
b=20
if [ $a -eq $b ]
then
echo "$a -eq $b : a 等于 b"
else
echo "$a -eq $b: a 不等于 b"
fi

浙公网安备 33010602011771号