linux shell---if condition

Syntax:

	if condition
	then
		command1 if condition is true or if exit status
		of condition is 0 (zero)
		...
		...
       fi                                                                                     
if given condition is true then command1 is executed
For compression you can use test or [ expr ] statements or even exist status can be also used.
eg.
#!/bin/bash
#
#Script to print file
#
if cat $1
then
echo -e "\n\nFile $1, found and successfully echoed"
fi
$0执行shell的时候表示的是shell name,$1表示执行shell时候传递的第一个参数,依次类推。$#表示执行shell的时候传递的参数的个数。
 

你可能感兴趣的:(linux shell---if condition)