#!/bin/bash
:<<eof
chmod +x ./test.sh #更改执行权限
expr 表达式 #求表达式的值
eof
:<<!
这也可用于多行注释
!
echo -e "hello world \nhello shell"
echo `date`
printf "%-10s %-8s %-4.2f\n" 你好 吗 11.123456
h0=helloshell
h='hello shell'
readonly h
unset h0
echo ${h}
str='this is a string'
newstr="I know that \"$str\",\n"
echo ${newstr:0:5}
echo ${#newstr}
echo `expr length "${newstr}"`
echo `expr index "$newstr" ir`
array=(1 2 3 4 5 6)
echo $array
array[0]=0
echo ${array[0]}
echo ${array[@]}
echo ${array[*]}
echo ${#array[*]}
echo "first:$0"
echo "second:$1"
third=$2
echo third:$third
echo $
echo $*
echo $$
echo $!
echo $@
echo $-
echo $?
a=2
b=5
echo `expr $a + $b`
echo `expr $a - $b`
echo `expr $a \* $b`
echo `expr $a / $b`
echo `expr $a % $b`
a=$b
echo ${a,b}
[ $a == $b ]
[ $a != $b ]
[ $a -eq $b ]
[ $a -ne $b ]
[ $a -gt $b ]
[ $a -lt $b ]
[ $a -ge $b ]
[ $a -le $b ]
[[ $a -lt 10 && $a -lt 10]]
[[ $a -lt 10 || $a -lt 10]]
str1='hello'
str2='world'
[ -z $str1 ]
[ -n $str1 ]
[ $str1 ]
if condition1
then
command1
command2
elif conditon2
then
command3
else
command4
fi
$ if [ conditon1 ]; then command1; elif [ condition2 ];then command3; else command4; fi
for i in item1 item2 item3 ... itemN
do
command1
command2
command3
done
$ for i in item1 item2 ... itemN; do command1; command2;...;done
while condition1
do
command
done
until condition
do
command
done
case 值 in
case1) command1 command2
;;
case2) command1 command2
;;
esac
fuction_name()
{
action;
[ return int;]
}
command > file
command < file
command >> file
n >& m
n <$ m
0:STDIN 1:STDOUT 2:STDERR