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
複製代碼