> shell编程 >

linux shell命令中if格式问题

#!/bin/bash

if [ $# = 2 ]; then  
echo "inpuT date is:" $1 ",time is:" $2  
date -s "$1 $2"  
fi  
 

  
说明:
$# = 2等号外面要有空格,中括号内外都要有空格,并且if后要加分号,否则会报错: 
syntax error near unexpected token `fi'。

注意,如果中括号中缺少空格,那么会报错if[ 2==2 ]: command not found。



 

(责任编辑:IT)