0

I need to test how a python TTS program reacts when a user input mistakenly two punctuation marks.

So I need to check the sentence "C'est un test!." (notice the !. at the end).

Consequently I input at prompt

  $ python3 /home/user1/TTS/bin/synthesize.py --text "C'est un test!."

But Bash then shows :

python3 /home/user1/TTS/bin/synthesize.py --text "This is a test./configure"

(notice how "!." changed into "./configure").

"This is a test!" (without period) works but I need to test "!.".

I tried and replaced double quotes with single quotes without success, and I tried and escaped "!" with "" but it is included in the sentence sent to the TTS library.

I understood that "!" has a special meaning in Bash (well explained here) and associated with "." it uses a previous command.

Is there a way to prevent Bash from processing "!." in the string and pass it as it is ?

Thanks for your help

  • "I tried and replaced double quotes with single quotes without success" -- A success was expected. – Kamil Maciorowski Oct 03 '22 at 05:17
  • @KamilMaciorowski I changed the sentence in the question to the one in French I am testing against (contains already an apostroph / single quote). That's why it failed, right ? – Cara Duf Oct 03 '22 at 08:19
  • It won't fail if you quote right. Example: python3 /home/user1/TTS/bin/synthesize.py --text "C'est un"' test!.'. Here the string is double-quoted to some point and single-quoted from the point. The point where quoting changes is almost arbitrary; it's only important your ' is double-quoted and ! is single-quoted. – Kamil Maciorowski Oct 03 '22 at 08:25
  • Thank you @KamilMaciorowski I get it now. I don't want to do that (parsing the user input, replace ! by "'!'", do all the edge cases...). I prefer the set +H solution below. – Cara Duf Oct 03 '22 at 08:28

1 Answers1

0

That's the history expansion. You can disable it altogether by using set +H or set +o histexpand or by setting $histchars to the empty string, or here you can use single quotes instead of double quotes. Outside of quotes, history expansion can also be disabled by prefixing ! with \.

According to set --help in bash:

-o option-name
Set the variable corresponding to option-name:
[...]
histexpand same as -H
[...]
-H
Enable ! style history substitution. This flag is on by default when the shell is interactive.
[...]
Using + rather than - causes these flags to be turned off.

You can try running these commands for checking the differences:

set -H
$> echo "hello!."
$> echo "hello!1"
$> !2
$> !3

set +H $> echo "hello!." $> echo "hello!1" $> !2 $> !3

  • Thank you set +H did the trick ! Happy to solve this annoying problem (I thought at first my computer had been compromised!!!). – Cara Duf Oct 03 '22 at 08:26
  • @TiTuS if you run your code in a bash script ( like myscrip.sh ) the history expansion is disabled by default. But If the shebang of your bash script is: #!/bin/bash -i the history expansion will be enabled. bash -i means that will run bash as interactive shell. – Edgar Magallon Oct 03 '22 at 21:13
  • Good to know thanks for this piece of information @Edgar. Actually I call a python script that needs arguments to be passed on so it is not run from a bash script. – Cara Duf Oct 04 '22 at 04:25