如何递增变量 - $var 包含字母 a..z
例子:
var=({b..z})
for x in 1 2 3 4 5
do
echo $x,$var
$var++ ( this is wrong but I need to do something like this )
done
预期输出:
1,b
2,c
3,d
4,e
5,f
.
.
.
答案1
简单的方法:
echo "$x,$var"
var="$(echo $var | tr '[a-y]z' '[b-z]a')"
答案2
你有一个数组;只需索引它:
var=( {b..z} )
for ((x=0; x<5; x++)); do
echo "$x, ${var[x+1]}"
done
答案3
paste -d, <( printf "%s\n" {1..25} ) <( printf "%s\n" {b..z} )
生产:
1,b
2,c
3,d
4,e
5,f
6,g
.
.
对于这样的系统:
OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution : Debian 8.9 (jessie)
bash GNU bash 4.3.30
paste (GNU coreutils) 8.23