+ -
当前位置:首页 → 问答吧 → 新手求教一个关于awk的简单脚本

新手求教一个关于awk的简单脚本

时间:2011-03-03

来源:互联网

#随机序列幻灯式演示, 关闭: 按两次 ALT+F4

#!/bin/bash

if [[ $# -lt 1 ]];then
echo 写入文件夹完整地址参数! 例:./prv.sh ~/Pictures/share/;
exit 0;
fi;

v_dir=$*;

if (echo $v_dir |grep -q '.*/.*');then
v_dir=$v_dir;
else
v_dir=$PWD;
fi;

if [[ ${v_dir:$((${#v_dir}-1)):1} != / ]];then
v_dir=$v_dir/;
fi;

v_picture_count=0;

for i in $(ls $v_dir);do
((v_picture_count++));
a_picture_name[$v_picture_count]=$i;
done;

for i in $(seq $v_picture_count);do
v_tmp=${a_picture_name[$i]};
v_random=$(($RANDOM%$v_picture_count+1));
a_picture_name[$i]=${a_picture_name[$v_random]};
a_picture_name[$v_random]=$v_tmp;
done;

i=1;

while [[ $i -le $v_picture_count ]];do

eog -fn $v_dir${a_picture_name[$i]}&
((i++));

if [[ $i -gt $v_picture_count ]];then
i=1;
for i in $(seq $v_picture_count);do
v_tmp=${a_picture_name[$i]};
v_random=$(($RANDOM%$v_picture_count+1));
a_picture_name[$i]=${a_picture_name[$v_random]};
a_picture_name[$v_random]=$v_tmp;
done;
fi;

sleep 3;

if [[ $(ps aux |grep -c eog) -eq 1 ]];then
exit 0;
else
v_eog=$(ps aux |grep eog |grep -v '\bgrep\b' |head -1);
v_eog=$(echo $v_eog |awk -F" " '{print $2}');
if [[ $(ps aux |grep -c eog) -gt 2 ]];then
kill $v_eog;
fi;
fi;

done;

作者: fnan   发布时间: 2011-03-03

热门下载

更多