我在 bash 脚本中声明数组中的所有可打印字符时遇到问题。I\xe2\x80\x99d 喜欢通过循环 4 次显示所有可打印字符。
\n\n例子
\n\narray=( a b c d \xe2\x80\xa6 z A B C \xe2\x80\xa6 Z 1 2 3 \xe2\x80\xa6 0 ! @ # $ % ^ & * ( ) _ +)\n\nFor chr1 in ${array[@]} \nDo\nFor chr2 in ${array[@]}\nDo \nEcho $chr1$chr2\nDone\nDone\nRun Code Online (Sandbox Code Playgroud)\n\n我已经能够使用 ${array[value of space]} 获取要打印的空格字符,但我仍然无法获取要打印的 * 字符。由于某种原因,它倾向于打印文件列表。
\n\n知道如何让它发挥作用吗?
\n引号!更多报价!
array=( a b c d z A B C Z 1 2 3 0 '!' '@' '#' '$' '%' '^' '&' '*' '(' ')' '_' '+')
for chr1 in "${array[@]}"
do
for chr2 in "${array[@]}"
do
echo "$chr1$chr2"
done
done
Run Code Online (Sandbox Code Playgroud)
在数组声明中的特殊字符周围加上引号,并在循环中的变量访问周围加上双引号。
| 归档时间: |
|
| 查看次数: |
4395 次 |
| 最近记录: |