编辑param.sh
#!/bin/bash
name="guo90"
echo $name
echo "hello, i know you are \"$name\""
for skill in Shell Python Java; do
echo "I am good at ${skill}Script"
done
for file in $(ls /home); do
echo "/home目录下子目录:$file"
done
readonlyVar=123
readonly readonlyVar
echo "只读变量readonlyVar:$readonlyVar"
readonlyVar=111
echo "下面开始拼接"
greeting2="hello, $name !"
echo $greeting1 $greeting2
echo ${#greeting1}
echo ${#greeting2}
greeting3='hello, '$name' !'
greeting4='hello, $name !'
echo $greeting3 $greeting4
echo ${#greeting3}
echo ${#greeting4}
echo "下面开始截取"
echo "greeting4的第3开始截取5位:${greeting4:3:5}"
echo "g在greeting3中第几位:"`expr index "$greeting3" g`
array_name=(guo 90)
echo "返回数组全部,${array_name[@]}"
echo "返回数组长度,${#array_name[@]}"
echo "返回元素1,${array_name[0]}"
echo "返回元素2,${array_name[1]}"
echo "返回元素2长度,${#array_name[1]}"
执行param.sh
./param.sh
guo90
hello, i know you are "guo90"
I am good at ShellScript
I am good at PythonScript
I am good at JavaScript
/home目录下子目录:admin
/home目录下子目录:tester1
只读变量readonlyVar:123
./param.sh: line 19: readonlyVar: readonly variable
下面开始拼接
hello, guo90 !
0
14
hello, guo90 ! hello, $name !
14
14
下面开始截取
greeting4的第3开始截取5位:lo, $
g在greeting3中第几位:8
返回数组全部,guo 90
返回数组长度,2
返回元素1,guo
返回元素2,90
返回元素2长度,2