iflistthenlist[eliflistthenlist]...[elselist]fi几种可能的写法--------------------------------------------------------------------------------第一种iflistthendosomethingherefi当list表述返回值为True(0)时,将会执行"dosomethinghere"。例一:当我们要执行一个命令或程式之前,有时候需要检查该命令是否存在,然後才执行。if[-x/sbin/quotaon];thenecho"TurningonQuotaforrootfilesystem"/sbin/quotaon/fi例二:当我们将某个档案做为设定档时,可先检查是否存在,然後将该档案设定值载入。#Filename:/etc/ppp/settingsPHONE=1-800-COLLECT#!/bin/sh#Filename:phonebillif[-f/etc/ppp/settings];thensource/etc/ppp/settingsecho$PHONEfi执行[foxman@foxmanppp]#./phonebill1-800-COLLECT--------------------------------------------------------------------------------第二种iflistthendosomethinghereelsedosomethingelseherefi例三:Hostname#!/bin/shif[-f/etc/HOSTNAME];thenHOSTNAME=`cat/etc/HOSTNAME`elseHOSTNAME=localhostfi--------------------------------------------------------------------------------第三种iflistthendosomethinghereeliflistthendoanotherthingherefi例四:如果某个设定档允许有好几个位置的话,例如crontab,可利用iftheneliffi来找寻。#!/bin/shif[-f/etc/crontab];thenCRONTAB="/etc/crontab"elif[-f/var/spool/cron/crontabs/root];thenCRONTAB="/var/spool/cron/crontabs/root"elif[-f/var/cron/tabs/root];thenCRONTAB="/var/cron/tabs/root"fiexportCRONTAB--------------------------------------------------------------------------------第四种iflistthendosomethinghereeliflistthendoanotherthinghereelsedosomethingelseherefi例五:我们可利用uname来判断目前系统,并分别做各系统状况不同的事。#!/bin/shSYSTEM=`uname-s`if[$SYSTEM="Linux"];thenecho"Linux"elif[$SYSTEM="FreeBSD"];thenecho"FreeBSD"elif[$SYSTEM="Solaris"];thenecho"Solaris"elseecho"What?"fi