#!/bin/sh
echo -n "login:"
read name
echo -n "password:"
read passwd
if [ "$name" = "aa" -a "$passwd" = "aaa" ];then
echo "right!"
else echo "error"
fi
一。运行过程中出现过 [: missing `]‘ 的问题,是[ "$name" = "aa" -a "$passwd" = "aaa" ] "$name"前和"aaa"后都必须要有空格。
二。if里面的-a相当于是与,-o相当于是或。还可以用&&和||表达。
if [ "$name" = "aa" -a "$passwd" = "aaa" ];then 与
if [ "$name" = "aa" -o "$passwd" = "aaa" ];then 或
if [ "$name" = "aa" ] && [ "$passwd" = "aaa" ];then 与
if [ "$name" = "aa" ] || [ "$passwd" = "aaa" ];then 或
&&是shell本身的语法支持 -a是shell的内部指令的用法 |
时间: 2024-11-05 23:22:42