CodeSnippet/shell/shell-freq.sh

45 lines
1.2 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# shell 的常用语法
# for 循环
for item in `ls`;
do
echo ${item} ;
done
# 数字for循环
for((i=1;i<=10;i++));
do
echo $(expr $i \* 3 + 1);
done
# 判断文件夹是否存在
if [ ! -d "/data/" ];then
mkdir /data
else
echo "文件夹已经存在"
fi
# 判断文件是否存在
if [ ! -f "/data/filename" ];then
echo "文件不存在"
else
rm -rf /data/filename
fi
# 循环判断pid是否还活着
while kill -0 $PID; do
sleep 1
done
# 常见的判断
# -e filename 如果 filename存在则为真 [ -e /var/log/syslog ]
# -d filename 如果 filename为目录则为真 [ -d /tmp/mydir ]
# -f filename 如果 filename为常规文件则为真 [ -f /usr/bin/grep ]
# -L filename 如果 filename为符号链接则为真 [ -L /usr/bin/grep ]
# -r filename 如果 filename可读则为真 [ -r /var/log/syslog ]
# -w filename 如果 filename可写则为真 [ -w /var/mytmp.txt ]
# -x filename 如果 filename可执行则为真 [ -L /usr/bin/grep ]
# filename1-nt filename2 如果 filename1比 filename2新则为真 [ /tmp/install/etc/services -nt /etc/services ]
# filename1-ot filename2 如果 filename1比 filename2旧则为真 [ /boot/bzImage -ot arch/i386/boot/bzImage ]