[20210322]seq xargs.txt
--//我经常使用seq xargs 执行脚本。上午测试时出现一些问题。
$ a=nccntnnn
--//我想实现每个字符显示1行。
$ seq 0 1 7 | xargs -IQ echo Q ${a:Q:1}
0 n
1 n
2 n
3 n
4 n
5 n
6 n
7 n
$ seq 8 | xargs -IQ echo Q ${a:Q:1}
1 n
2 n
3 n
4 n
5 n
6 n
7 n
8 n
--//很明显${a:Q:1}中里面的Q是相当于没有定义。相当于执行的是
$ echo ${a::1}
n
--//只能使用expr来完成测试:
$ seq 8 | xargs -IQ expr substr $a Q 1
n
c
c
n
t
n
n
n
--//也就是使用-I中的替换不能发生在shell变量中。
$ seq 8 | xargs -IQ bash -c "echo -n Q:;expr substr $a Q 1"
1:n
2:c
3:c
4:n
5:t
6:n
7:n
8:n
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-2764251/ ,如需转载,请注明出处,否则将追究法律责任。