linux shell---if condition

来源:互联网 发布:淘宝一伍一拾 编辑:程序博客网 时间:2024/06/10 23:53

Syntax:

if conditionthencommand1 if condition is true or if exit statusof 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的时候传递的参数的个数。
原创粉丝点击