免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1344 | 回复: 0
打印 上一主题 下一主题

shell文件存在的判断 shell数组 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-08-10 16:19 |只看该作者 |倒序浏览


  shell文件存在的判断 shell数组
[url=JavaScript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(saveit=window.open('http://wz.csdn.net/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'saveit','scrollbars=no,width=590,height=300,left=75,top=20,status=no,resizable=yes'));saveit.focus();]收藏[/url]

判断文件:
    WORKDIR=/home/tmp
    LOCAL_LIST_FILE=$WORKDIR/local.list
    #if no local.txt file, generate a new one
    if [ ! -f  "$LOCAL_LIST_FILE" ]; then
      touch $LOCAL_LIST_FILE
    fi
    注意:一定要有空格,判断文件是否存在,如果不存在,就生成一个新的
    if [ ! -d /mnt ]        # be sure the directory /mnt exists
       then
           mkdir /mnt
    fi
   
    目录。/mnt是否存在,不存在就生成目录/mnt
The tests below are test conditions provided by the shell:
    * -b file = True if the file exists and is block special file.
    * -c file = True if the file exists and is character special file.
    * -d file = True if the file exists and is a directory.
    * -e file = True if the file exists.
    * -f file = True if the file exists and is a regular file
    * -g file = True if the file exists and the set-group-id bit is set.
    * -k file = True if the files' "sticky" bit is set.
    * -L file = True if the file exists and is a symbolic link.
    * -p file = True if the file exists and is a named pipe.
    * -r file = True if the file exists and is readable.
    * -s file = True if the file exists and its size is greater than zero.
    * -s file = True if the file exists and is a socket.
    * -t fd = True if the file descriptor is opened on a terminal.
    * -u file = True if the file exists and its set-user-id bit is set.
    * -w file = True if the file exists and is writable.
    * -x file = True if the file exists and is executable.
    * -O file = True if the file exists and is owned by the effective user id.
    * -G file = True if the file exists and is owned by the effective group id.
    * file1 –nt file2 = True if file1 is newer, by modification date, than file2.
    * file1 ot file2 = True if file1 is older than file2.
    * file1 ef file2 = True if file1 and file2 have the same device and inode numbers.
    * -z string = True if the length of the string is 0.
    * -n string = True if the length of the string is non-zero.
    * string1 = string2 = True if the strings are equal.
    * string1 != string2 = True if the strings are not equal.
    * !expr = True if the expr evaluates to false.
    * expr1 –a expr2 = True if both expr1 and expr2 are true.
    * expr1 –o expr2 = True is either expr1 or expr2 is true.
Shell中的数据问题
   ArrayName=("element 1" "element 2" "element 3")  #数组定义
   echo ${#ArrayName[@]}
  echo "The number of elements in the array is ${#ArrayName
  • }"     
       
        例子
        #!/bin/bash
        # define array
        # name server names FQDN
        NAMESERVERS=("ns1.nixcraft.net." "ns2.nixcraft.net." "ns3.nixcraft.net.")

        # get length of an array
         tLen=${#NAMESERVERS[@]}

        # use for loop read all nameservers
        for (( i=0; i


    本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/15566/showart_2023556.html
  • 您需要登录后才可以回帖 登录 | 注册

    本版积分规则 发表回复

      

    北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
    未成年举报专区
    中国互联网协会会员  联系我们:huangweiwei@itpub.net
    感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

    清除 Cookies - ChinaUnix - Archiver - WAP - TOP