核心代码 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/access.log" #这里的-x 参数判断$myPath是否存在并且是否具有可执行权限 if [ ! -x "$myPath"]; then mkdir "$myPath" fi #这里的-d 参数判断$myPath是否存在 if [ ! -d "$myPath"]; then
前提:文件最后一行有换行符 第一步:以二进制方式取得文件最后两个byte.last2=`tail -c 2 <your_file> | od -x -A n` 第二步:判断最后两个byte是否是'CRLF'if [ $last2 = 0a0d -o $last2 = 0d0a ]then # Cheating! If the file ends in LFCR, it would incorrectly # say that it is CRLF echo File ends in CRLFf
#!/bin/bash directory="/path/to/directory" if [ $(ls -A $directory) ]; then echo "有文件" # 执行指定shell脚本 sh /path/to/script.sh else echo "没有文件" fi #!/bin/bash directory="/path/to/directory"if [ "$(ls -A $directory)
#!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/access.log" #这里的-x 参数判断$myPath是否存在并且是否具有可执行权限 if [ ! -x "$myPath"]; then mkdir "$myPath" fi #这里的-d 参数判断$myPath是否存在 if [ ! -d "$myPath"]; then mkdi