質問

to make hangman i replace a words letters with "_" i do this using

echo $word|tr -c $guessed _ 

which works but it creates an extra _ at the end of the word. How do i get rid of him?

Thanks in advance

EDIT: I found out on my own. The extra _ is the "return" that echo produces replaced by _

echo -n $word|tr -c $guessed _

this works like a charm

役に立ちましたか?

解決

echo puts in a newline character at the end of its output, which tr is converting. This is often the desired behavior, hence it being the default. Imagine echo hello on the terminal; you want a newline there so your prompt returns.

You can use the -n option to echo to fix the above behavior. This information can be found in man 1 echo:

-n     do not output the trailing newline
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top