在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ Linux/ Shell 文件測試符例子
Shell 輸入/輸出重定向
Shell 循環(huán)類型
Shell是什么?
Shell 特殊變量
Shell 算術運算符示例
Shell 關系運算符示例
Shell 替代
Shell 函數(shù)
Shell 條件語句
Shell 聯(lián)機幫助
Shell 數(shù)組/Arrays
Shell 布爾運算符范例
Shell
Shell if...elif...fi 語句
Shell case...esac 語句
Shell 使用Shell變量
Shell 文件測試符例子
Shell 基本運算符
Korn Shell 運算符
Shell 字符串運算范例
Shell while 循環(huán)
Shell 引用機制
Shell if...else...fi 語句
Shell select 循環(huán)
C Shell運算符
Shell 循環(huán)控制break/continue
Shell for循環(huán)
Shell until 循環(huán)
Shell if...fi語句

Shell 文件測試符例子

下面是一個例子,它使用的所有文件測試操作:

假設一個變量的文件保存現(xiàn)有文件名"/var/www/yiibai/unix/test.sh",其大小為100字節(jié),讀,寫和執(zhí)行權限:

#!/bin/sh

file="/var/www/yiibai/unix/test.sh"

if [ -r $file ]
then
   echo "File has read access"
else
   echo "File does not have read access"
fi

if [ -w $file ]
then
   echo "File has write permission"
else
   echo "File does not have write permission"
fi

if [ -x $file ]
then
   echo "File has execute permission"
else
   echo "File does not have execute permission"
fi

if [ -f $file ]
then
   echo "File is an ordinary file"
else
   echo "This is sepcial file"
fi

if [ -d $file ]
then
   echo "File is a directory"
else
   echo "This is not a directory"
fi

if [ -s $file ]
then
   echo "File size is zero"
else
   echo "File size is not zero"
fi

if [ -e $file ]
then
   echo "File exists"
else
   echo "File does not exist"
fi

這將產(chǎn)生以下輸出結果:

File has read access
File has write permission
File has execute permission
File is an ordinary file
This is not a directory
File size is zero
File exists

記下以下幾點:

  • 運算符和表達式之間必須有空格,例如2+2是不正確的,它應該寫成2 + 2。

  • if...then...else...fi 語句在下一章節(jié)中已經(jīng)解釋的決策聲明。