linux 中生成两个变量任意的两两组合(Any pairwise combination of two variables generated in Linux)

1、

root@PC1:/home/test# ls
root@PC1:/home/test# for i in {A..D}; do for j in {A..D}; do echo $i"_"$j; done; done  ## 生成A-D任意的两两组合
A_A
A_B
A_C
A_D
B_A
B_B
B_C
B_D
C_A
C_B
C_C
C_D
D_A
D_B
D_C
D_D

2、

root@PC1:/home/test# ls
root@PC1:/home/test# for i in {A..D}{A..D}; do echo $i; done
AA
AB
AC
AD
BA
BB
BC
BD
CA
CB
CC
CD
DA
DB
DC
DD

参考:https://mp.weixin.qq.com/s?__biz=MzA4NzQzMzU4Mg==&mid=2652979038&idx=2&sn=ce399516779f83a53fdba74d383be9e0&chksm=8bec175fbc9b9e495f5935a2b4efdcbeff2fbca3d2145f87ee6acc7ef6a0220f0e2718d2aef0&mpshare=1&scene=23&srcid=0115mGMZcZjWkjYGSq6wem4g&sharer_sharetime=1642235406934&sharer_shareid=4ed060cc4cd1efce40e3ab6dd8d8c7d4#rd

————————

1、

root@PC1:/home/test# ls
root@PC1:/home/test# for i in {A..D}; do for j in {A..D}; do echo $i"_"$j; done; done  ## 生成A-D任意的两两组合
A_A
A_B
A_C
A_D
B_A
B_B
B_C
B_D
C_A
C_B
C_C
C_D
D_A
D_B
D_C
D_D

2、

root@PC1:/home/test# ls
root@PC1:/home/test# for i in {A..D}{A..D}; do echo $i; done
AA
AB
AC
AD
BA
BB
BC
BD
CA
CB
CC
CD
DA
DB
DC
DD

参考:https://mp.weixin.qq.com/s?__biz=MzA4NzQzMzU4Mg==&mid=2652979038&idx=2&sn=ce399516779f83a53fdba74d383be9e0&chksm=8bec175fbc9b9e495f5935a2b4efdcbeff2fbca3d2145f87ee6acc7ef6a0220f0e2718d2aef0&mpshare=1&scene=23&srcid=0115mGMZcZjWkjYGSq6wem4g&sharer_sharetime=1642235406934&sharer_shareid=4ed060cc4cd1efce40e3ab6dd8d8c7d4#rd