【发布时间】:2017-08-20 23:02:38
【问题描述】:
我的伙伴之前在 unix SE 上问过这个问题,但他问错了。他也没有得到有效的答案。
无论如何,我正在尝试让我的 bash 脚本处理变量中的每个字符,并为每个字母回显某个字符串,直到它到达最后一个。到目前为止,这是我所拥有的:
#!/bin/bash
echo Word?
read -r -p '' foo
# $foo is set to 'Mammals and Bricks' by user.
wordlength=${#foo}
$wordlength says 18, so start on character 1.
'M' is first letter received in $foo, so echo '{m,M}'
'a' is second letter received in $foo, so echo '{a,A}'
'm' is third letter received in $foo, so echo '{m,M}'
'm' is fourth letter received in $foo, so echo '{m,M}'
'a' is the fifth letter received in $foo, so echo '{a,A}'
'l' is the sixth letter received in $foo, so echo '{l,L}'
's' is the seventh letter received in foo, so echo '{s,S}'
' ' is the eighth, so echo '\ '
........
'c' is sixteenth letter received in $foo, so echo '{c,C}'
'k' is seventeenth letter received in $foo, so echo '{k,K}'
's' is eighteenth letter received in $foo, so echo '{s,S}'
这就是它在用户端的样子:
Word?
哺乳动物和砖块
{m,M}{a,A}{m,M}{m,M}{a,A}{l,L}{s,S} {a,A}{n,N}{d,D} {b,B}{r,R}{i,I}{c,C}{k,K}{s,S}
确切会输出什么。您会以原始字符形式看到上述所有内容。
有人知道怎么做吗?
【问题讨论】:
标签: bash osx-yosemite