1. 程式人生 > >Linux-條件組合測試

Linux-條件組合測試

linux

if [ $1 == ‘-add‘ ] ;then

for i in `echo $2 | sed ‘s/,/ /g‘`;do

if id $i &> /dev/null;then

echo "user exists."

else useradd $i

echo $i | passwd --stdin $i &> /dev/null

echo "useradd...$i"

fi

done

elif [ $1 == ‘-del‘ ];then

for i in `echo $2 | sed ‘s/,/ /g‘`;do

if id $i &> /dev/null;then

userdel -r $i

echo "userdel...$i"

else

echo "user not exists."

fi

done

else

echo "command:user.sh -add/-del col1,col2,col3...."

fi




組合條件測試。

-a:與關系

-o:或關系

!:非關系


if [ $# -gt 1 -a $# -le 3 ]

if [ $# -gt 1] && [ $# -le 3 ]


#!/bin/bash

#

if [ $1 == ‘q‘ -o $1 == ‘Q‘ -o $1 == ‘quit‘ -o $1 == ‘Quit‘ ];then

echo "quiting"

exit 0

else

echo "unkonwn arg"

exit 1

fi


#!/bin/bash

#

envsum=0

oddsum=0

for i in {1..100};do

if [ $[$i%2] -eq 0 ];then

let envsum+=$i

else

let oddsum+=$i

fi

done

echo $envsum

echo $oddsum





Linux-條件組合測試