<<EOF
this shell is for test
this shell is for test
EOF
echo -e "\"Hello\nworld\""
echo '$$'
echo "\$\$"
echo `date`
echo $(date)
echo "the script name is `basename $0`"
echo "var nums:$#"
echo "all user vars:$*"
echo "all user vars:$@"
text="123456"
length=${#text}
echo ${text:2:($length-3)}
echo `expr index ${text} 34`
color=(red yellow blue)
echo ${color[1]}
echo "${color[*]}"
echo "${color[@]}"
echo "${#color[*]}"
printf "+ %s\n" "${color[@]}"
echo ${#color[@]}
color=(white ${color[@]} black)
unset color[1]
echo ${color[@]}
x=10
y=20
if [ ${x} != ${y} ]
then
echo `expr $x \* $y`
elif [ ${x} -ge 10 ]
then
echo "x is greater than 10"
else
echo "others"
fi
if [ ${x} -gt 1 -o ${y} -gt 1 ]
then echo "x,y are greater than 1"
fi
text2="12"
if [ -n "${text2}" ]
then echo "length of ${text2} is not 0"
fi
if [ -z "${text2}" ]
then echo "length of ${text2} is 0"
fi
if [ ${text2} ]
then echo "${text2} is not empty"
fi
text3="a"
case ${text3} in
"a")
echo "a";;
"b")
echo "b";;
esac
function moveFile {
sourceDir="$1"
targetDir="$2"
for FILE in ${sourceDir}/*.txt; do
mv "$FILE" "${targetDir}"
done
}
sourceDir="`pwd`"
targetDir="`pwd`/text"
touch newFile.txt
chmod 777 newFile.txt
if [ -d ${targetDir} ]
then
echo "dir ${targetDir} exists"
moveFile ${sourceDir} ${targetDir}
else
echo "dir ${targetDir} not exists, create a dir"
mkdir -m 777 ${targetDir}
moveFile ${sourceDir} ${targetDir}
fi
ls -l ${targetDir}
for ((i = 0; i < 3; i++)); do
echo "i=${i}"
done
j=0
j=$((j+1))
j=`expr $j + 1`
while [[ $j < 5 ]]; do
j=$((j + 1))
echo "j=${j}"
done
x=0
set -x
until [[ $x -ge 3 ]]; do
x=$((x + 1))
echo "x=${x}"
done
set +x
cat <<-EOF >>newFile2.txt
hello
hi
EOF
cat newFile2.txt