歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> linux腳本中關於檢查文件的代碼

linux腳本中關於檢查文件的代碼

日期:2017/2/25 10:38:18   编辑:Linux教程
 #!/#!/bin/bash

  # check file......

  PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin

  export PATH

  test -e /tmp/logical && test_e=0 || test_e=1

  test -f /tmp/logical && test_f=0 || test_f=1

  test -d /tmp/logical && test_d=0 || test_d=1

  if [ "$test_e" == "1" ];then

  `touch /tmp/logical`

  else

  if [ "$test_f" == "0" ];then

  `rm /tmp/logical`;`touch /tmp/logical_one`

  fi

  if [ "$test_d" == "0" ];then

  `rm /tmp/logical/`

  fi

  fi

  原意想根據test返回值直接進行判斷,可惜每次獲取的返回值都是0,無可奈何下采用了設置幾個變量來判斷。如果有知道如何根據test來判斷的,麻煩說下。 Thanks

  為了這段代碼,還特意安裝了linux vmware tools,實現文件共享,希望對大家有用。

Copyright © Linux教程網 All Rights Reserved