Last active
July 12, 2019 08:26
-
-
Save chenzhg33/b315c963125d334a6f36238f84aaa6de to your computer and use it in GitHub Desktop.
Shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
baseName=$(basename $0) | |
usage() { | |
echo Usage: ./$baseName cmd concurrent | |
exit 127 | |
} | |
cmd="$1" | |
concurrent=$2 | |
seq 1 100000000000 | xargs -I'{}' -n1 -P$concurrent sh -c "$cmd" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+++++将字符串分割成数组,类似split: | |
1 arr=(`echo $str | tr "delimit" " "`) | |
2 IFS="delimit"; arr=($str) #要保存原有的IFS,得多加语句 | |
++++++字符串截取: | |
假设变量 str 值为 oh_123_my_123_god | |
## 为从左到右匹配,尽多匹配,然后去掉匹配的字符串 | |
# 为从左到右匹配,尽少匹配,然后去掉匹配的字符串 | |
%% 为从右到做匹配,尽多匹配,然后去掉匹配的字符串 | |
% 为从右到做匹配,尽少匹配,然后去掉匹配的字符串 | |
格式 | |
含义 | |
样例 | |
${varible##*string} | |
从左向右截取最后一个string后的字符串 | |
${str##*123} = _god | |
${varible#*string} | |
从左向右截取第一个string后的字符串 | |
${str#*123} = _my_123_god | |
${varible%%string*} | |
从右向左截取最后一个string后的字符串 | |
${str%%123*} = oh_ | |
${varible%string*} | |
从右向左截取第一个string后的字符串 | |
${str%123*} = on_123_my_ | |
${varible:a:b} | |
++++++read从字符串输入 | |
read -a arr <<< $(echo $str) | |
++++++打印有颜色的字符串 | |
echo -e "\e[1;33m这些字都是有颜色的\e[0m" 1>&2 | |
\e[ 后面的控制样式: | |
0 关闭所有属性 | |
1 设置高亮度 | |
4 下划线 | |
5 闪烁 | |
7 反显 | |
8 消隐 | |
30 黑色字 | |
31 红色字 | |
32 绿色字 | |
33 黄色字 | |
34 蓝色字 | |
35 紫色字 | |
36 天蓝字 | |
37 白色字 | |
40~47控制字的背景色,40是黑色背景,41是红色.... | |
++++++ 需要打印多行文字的时候 | |
conf=$(cat <<EOF | |
uid=qspace | |
gid=users | |
EOF) | |
echo -e "$conf" #这里的双引号必须加 | |
++++++ $* 和 $@ 详解 (结论:推荐用"$@",做参数传递), https://unix.stackexchange.com/questions/41571/what-is-the-difference-between-and | |
1 $* 和 $@ 没有被 "" 包围,则这两者一样,千万不要用于参数传递,比如 a b "c d" ,会被当成 a b c d处理 | |
2 "$*" 和 "$@" 有区别 | |
"$*" 用IFS变量的第一个字符将所有参数连接起来,可用于参数连接 | |
"$@" 则会保留原来参数的完整样子,即使参数中含义空格 | |
测试用例: | |
a.sh | |
echo $# | |
IFS="-bj" | |
echo "$*" | |
sh b.sh "$@" | |
b.sh | |
echo $# | |
echo;echo "\$@"; for i in $@;do echo $i;done | |
echo;echo "\"\$@\""; for i in "$@"; do echo $i; done | |
echo;echo "\$*"; for i in $*; do echo $i; done | |
echo;echo "\"\$*\"";for i in "$*";do echo $i; done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment