-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxfor
More file actions
43 lines (42 loc) · 1 KB
/
Copy pathxfor
File metadata and controls
43 lines (42 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
source ~/command/common
if [ -z "$1" -o "$1" = "-h" -o "$1" = "--help" ];then
echo "Usage:"
echo " xfor command: 使用clipboard的内容,如:复制'a b c'执行'xfor \"echo #i#i\"'会显示'aa bb cc'"
echo " xfor 10 command: 从0开始"
echo " xfor 3 10 command: 从3开始"
echo " xfor 3 10 2 command: 从3开始,步长为2,可以为-1"
echo " command: \"echo #i\""
exit
fi
if [ $# = '1' ];then
if __mac ;then
str=`pbpaste`
else
str=`cat /dev/clipboard`
fi
__ask "执行${str}吗"
if [ "$?" = "$_FALSE_" ];then
exit
fi
str=($str)
for i in "${str[@]}";do
${1//#i/$i}
done
elif [ $# = '2' ];then
for ((i=0; i<=$1; i++));do
${2//#i/$i}
done
elif [ $# = '3' ];then
for ((i=$1; i<=$2; i++));do
${3//#i/$i}
done
elif [ $3 -lt 0 ];then
for ((i=$1; i>=$2; i+=$3));do
${4//#i/$i}
done
else
for ((i=$1; i<=$2; i+=$3));do
${4//#i/$i}
done
fi