Bash显示charcaters如果不是在字符串 [英] Bash show charcaters if not in string

查看:163
本文介绍了Bash显示charcaters如果不是在字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



一切正常,但我不明白如何做一件事:



我向用户显示了带有猜测字母的单词(例如世界是hello world,用户猜到了'l' ll * *** l *)



我存储用户已经尝试过的字母var guess



我这样做与以下:

  echo$ {word // [^ [:space:] $ guess] / * }

我现在要做的事情是回声字母表,用户已经尝试了,所以在这种情况下显示没有L的完整字母表。



我已经尝试以和我刚才显示的相同的方式做,



如果您需要更多信息,请告诉我。



谢谢,

解决方案

您不会显示您尝试的内容,但参数扩展可以正常工作。

  $ alphabet = abcdefghijklmnopqrstuvwxyz 
$ word =hello world
$ guesses = aetl
$ echo$ {word / / [^ [:space:] $ guesses] / *}
* el * *** l *
$ echo$ {alphabet // [$ guesses] / *}
* bcd * fghijk * mnopqrs * uvwxyz


I am trying out bash, and I am trying to make a simple hangman game now.

Everything is working but I don't understand how to do one thing:

I am showing the user the word with guessed letters (so for example is the world is hello world, and the user guessed the 'l' I show them **ll* ***l* )

I store the letters that the user already tried in var guess

I do that with the following:

echo "${word//[^[:space:]$guess]/*}"

The thing I want to do now is echo the alphabet, but leave out the letters that the user already tried, so in this case show the full alphabet without the L.

I already tried to do it the same way as I shown just yet, but it won't quite work.

If you need any more info please let me know.

Thanks, Tim

解决方案

You don't show what you tried, but parameter expansion works fine.

$ alphabet=abcdefghijklmnopqrstuvwxyz
$ word="hello world"
$ guesses=aetl
$ echo "${word//[^[:space:]$guesses]/*}"
*ell* ***l*
$ echo "${alphabet//[$guesses]/*}"
*bcd*fghijk*mnopqrs*uvwxyz

这篇关于Bash显示charcaters如果不是在字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆