1.for循环
for ##定义变量
do ##使用变量,执行动作
done ##结束标志
循环的四种格式
#!/bin/bash
for WESTOS in seq 1 2 10
do
echo $WESTOS
done
2. for WESTOS in 1 2 3
do
echo $WESTOS
done
3. for WESTOS in {10…1}
do
echo $WESTOS
done
4.for ((WESTOS=0;WESTOS<10;WESTOS++))
do
echo $WESTOS
done
2. 循环
while ture #条件为真
do #条件成立所作循环动作
3.until循环
until false ##条件为假
do #条件不成立所作循环动作
done
4.if语句
if
then
elif
then
…
else
fi
5.case语句
case $1 in
word1|WORD1)
action1
;;
word2|WORD2)
action2
;;
*)
action3
esac
6.expect问答脚本
问题脚本
#!/bin/bash
read -p “what’s your name:” NAME
read -p "How old are you: " AGE
read -p "Which objective: " OBJ
read -p "Are you ok? " OK
echo $NAME is $AGE’s old study $OBJ feel $OK
应答脚本
#!/usr/bin/expect
set timeout 1
set NAME [ lindex $argv 0 ]
set AGE [ lindex $argv 1 ]
set OBJ [ lindex $argv 2 ]
set FEEL [ lindex KaTeX parse error: Expected '}', got 'EOF' at end of input: …name" { send "NAME\r";exp_continue }
“old” { send “KaTeX parse error: Can't use function '\r' in math mode at position 4: AGE\̲r̲";exp_continue …OBJ\r”;exp_continue }
“ok” { send “$FEEL\r” }
}
expect eof