Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含数字的变量,使用 shell 脚本如何将数字转换为星号字符,例如 5 将转换为*****, 2 将转换为**
*****
**
简单的解决方案是使用 perl:
VAR=5 perl -e "print '*' x $VAR"
其他解决方案是使用seq:
seq
VAR=5 for i in `seq $VAR` ; do echo -n '*' ; done
尝试这样做:
$ echo "azerty5qwerty5" | perl -pe 's/5/sprintf "%s", "," x $&/ge' azerty,,,,,qwerty,,,,,