I'm trying to make a service to translate things which Chrome doesn't translate automatically. The following script works when run from my shell

    #!/bin/bash

	input='это тест)))' # translates to - this is a test)))
	if [[ $(echo "$input") =~ ')' ]]; then 
		input="$(echo "${input//)/}")"
	fi
	export PATH="/usr/local/bin:$PATH"; /usr/local/bin/trans -e yandex -b :en "$input" 

the result: `this is a test`

However when I put this into an Applescript:

	set input to "это тест)))"
	set output to (do shell script "if [[ $(echo " & quoted form of input & ") =~ ')' ]]; then " & quoted form of input & "=\"$(echo \"${" & quoted form of input & "//)/}\")\"; fi; export PATH=\"/usr/local/bin:$PATH\"; /usr/local/bin/trans -e google -b :en " & quoted form of input & "")

	display dialog output as string

The result is still `this is a test)))`

It still runs and translates the input string. But it doesn't remove the `)))`. I don't understand why the `if` statement is not working in my applescript version. Am I quoting something wrong? 

This script uses a program called **Translate-Shell** which can be found on [GitHub](https://github.com/soimort/translate-shell) or at the program author's website [here](https://www.soimort.org/translate-shell/).