財神娛樂首存即享優惠回饋唷~詳情請進👉

使用Bash Shell吃角子老虎機台反省文件是否存在的要領

媒介

人人在事情的時辰可能常常會碰到如許的需求,在類Unix體系的Bash情況下,奈何反省文件是否存在呢?既然有需求,當然就有辦理的設施了,Shell中的test下令,可以用來檢測文件的類型或者者比較數值是否相等,該下令也能用來反省文件是否存在。

可以用以下的下令來進行反省:

test -e filename
[ -e filename ]
 
test -f file六合彩規則name
[ -f filename ]

上面的下令,則使用Shell的前提抒發式,判定/etc/hosts文件是否存在:

[ -f /偏財運意思etc/hosts ] && echo 公眾Found"大眾 || echo "大眾Not found公眾

該組合下令會輸入如下內容:

Found

更常見的用法,則是將test下令放置在if..else..fi前提判定的前提抒發式,然后在個中寫上不同的分支邏輯

#!/bin/bash
file="大眾/etc/hosts"大眾
if [ -f "大眾$file"大眾 ]
then
 echo "大眾$file found."大眾
else
 echo "大眾$file not found."大眾
fi

檢測文件屬性的相關操作符

若是文件存在,而且具備響應的屬性,以下的操作符都邑返歸true:

  -b FILE
    FILE exists and is block special
  -c FILE
    FILE exists and is character special
  -d FILE
    FILE exists and is a directory
  -e FILE
    FILE exists
  -f FILE
    FILE exists and is a regular file
  -g FILE
    FILE exists and is set-group-ID
  -G FILE
    FILE exists and is owned by the effective group ID
  -h FILE
    FILE exists and is a symbolic link (same as -L)
  -k FILE
    FILE exists and has its sticky bit set
  -L FILE
    FILE exists and is a symbolic link (same as -h)
  -O FILE
    FILE exists and is owned by the effective user ID
  -p FILE
    FILE exists and is a named pipe
  -r FILE
    FILE exists and read permission is granted
  -s FILE
    FILE exists and has a size greater than zero
  -S FILE
   地下539公式 FILE exists and is a socket
  -t FD file descriptor FD is opened on a terminal
  -u FILE
    FILE exists and its set-user-ID bit is set
  -w FILE
    FILE exists and write permission is granted
  -x FILE
    FILE exists and execute (or search) permission is granted

以上下令,從man test復制而來。

使用上述符號的要領截然不同:

if [ operator FileName ]
then
  echo 玩運彩公眾FileName - Found,take some action here公眾
else
 echo 公眾FileName - Not found,take some action here"大眾
fi

總結

以上便是這篇文章的掃數內容了,但愿本文的內容對人人的進修或者者事情能帶來肯定的輔助,若是有疑難人人可留言交流。

【免責聲明】本站內容轉載自互聯網,其相關談吐僅代表作者小我私家概念盡非權勢巨子六合彩玩法规则,不代表本站態度。如您發明內容存在版權成績,請提交相關鏈接至郵箱:,咱們將實時予以處置。