Say the following Bash script:
#!/bin/bash
export TEXTDOMAINDIR=./locale
export TEXTDOMAIN=test-gettext-read
. gettext.sh
echo -n $(gettext "Insert a word: ")
read word
GNU gettext is used to make the string translatable and read is used to get user input. However, even if there’s a trailing space in the gettext message, there’s no space in the terminal when I run the script. Example (cursor is |):
$ bash test-gettext-read.sh
Insert a word:|
As a workaround, I remove the trailing space in the gettext string and I add a space outside:
echo -n $(gettext "Insert a word:")" "
Then it works:
$ bash test-gettext-read.sh
Insert a word: |
My question: is there a better workaround?
Thanks a lot.
Dont use
echo -n.Simply do this:
Or you could wrap your expression whit quotes and then pass it to echo:
Using quotes will ensure that the result passed to echo will be interpreted as one parameter
"Insert a word: "insteand of 3:'Insert''a''word:'.