Shell string manipulation not working in Applescript
It doesn't work because, the shell try to change a 'string', not to set a variable.

The command as example:

do shell script "if [[ $(echo " &amp; quoted form of input &amp; ") =~ ')' ]]; then " &amp; quoted form of input &amp; "=\"$(echo \"${" &amp; quoted form of input &amp; "//)/}\")\"; fi; "


After the concatenation (Look at the Events in the script editor), the command is:


  do shell script "if [[ $(echo 'это тест)))') =~ ')' ]]; then 'это
  тест)))'=\"$(echo \"${'это тест)))'//)/}\")\"; fi; "




So, put the content of the AppleScript's variable into a variable in the shell (I remove the echo commands, because it's useless), like this:

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