echo "hello world"
复制代码
chmod +x ./helloworld.sh
复制代码
/bin/sh helloworld.sh
复制代码
设置变量shell
test ="hello";
复制代码
取出变量数组
$test
${test}
复制代码
删除变量bash
unset test
复制代码
设置字符串函数
str ="hello"
复制代码
拼接字符串学习
str1 ="world"
str2 ="hello ${str1}"
复制代码
字符串长度ui
str1 ="world"
${#str1}
复制代码
定义数组spa
array=(str1,str2,str3,str4)
复制代码
数组赋值code
array[0]="hello"
复制代码
读取数组cdn
${array[0]}
复制代码
数组长度blog
${#array[*]}
复制代码
echo
echo "hello"
复制代码
printf
printf("world")
复制代码
> 定向输出
"hello world" > a.txt
复制代码
>> 追加 定向输出
"hello world" >> a.txt
复制代码
IF
a=10
b=20
if [ $a == $b ]
then
printf("hello")
fi
复制代码
ELSE
if [ $a == $b ]
then
printf("hello")
elif
then
echo("world")
fi
复制代码
FOR
for entry in 1 2 3 4 5
do
echo "The value is: $entry"
done
复制代码
WHILE
index =1
while(( $index<=100 ))
do
echo $index
let "index++"
done
复制代码
shell_fun(){
echo "hello"
}
shell_fun(){
return "hello"
}
复制代码
./hello_world hello world 1 45
$0 hello_world
$1 hello
$2 world
$3 1
$4 45
echo $0 ------> echo hello_world
复制代码