首页未分类 › 结构化命令

结构化命令

1.if-then

if command

then

command

fi

[root@db-grassroots-61-001 script]# cat 2
#!/bin/bash
testuser=markgeng
if grep $testuser /etc/passwd
then
echo Then bash files for user $testuser are:
ls -a /home/$testuser/.b*
fi

2.if -then-else

if command

then

command

else

command

fi

[root@db-grassroots-61-001 script]# cat 2
#!/bin/bash
testuser=markgeng
if grep $testuser /etc/passwd
then
echo Then bash files for user $testuser are:
ls -a /home/$testuser/.b*
else
echo “The user name $testuser doesn’t exist on this system”

fi

3.嵌套if语句

if command1

then

commands

elif command2

then

more commands

fi

4.if-then -elif

if command1

then

command set 1

elif command2

then

command set 2

elif command3

then

command set 3

elif command4

then

  command set 4

fi

发表评论