-1

I have an EC2 instance with Tomcat instance running and the credential to connect the tomcat instance is stored in the aws secret manager. Now when i read the password from secret manager i get the correct output

aws secretsmanager get-secret-value --secret-id tomcat_creds --query SecretString --output text | cut -d: -f3 | tr -d \"\}

Output : !c$674

But when i input the above output as a password for my tomcat url using curl, it is failing due to the characters ! $ .

curl -s -u ${USER}:${PASS} ${URL} 

Now i am trying to convert the received output from !c$674 to /!c/$674 before providing as an input to curl command.

is there any way we can convert the above in shell scripts. I am new to shell scripts.

Jijo John
  • 61
  • 1
  • 7
  • Putting escapes or quotes in a variable doesn't (usually) do anything useful; see ["Why does shell ignore quoting characters in arguments passed to it through variables?"](https://stackoverflow.com/questions/12136948) Generally, what you need to do is put double-quotes *around* variable references (e.g. `"${USER}:${PASS}"` instead of `${USER}:${PASS}`) (but you should use lower- or mixed-case variable names -- some all-caps names, including `USER`, have special meanings). Your problem may be somewhere else, however; try putting `set -x` before this section, and see what the trace shows. – Gordon Davisson Jan 21 '22 at 17:03
  • @GordonDavisson - This solution worked. After modifying to "${USER}:${PASS}" instead of ${USER}:${PASS}. Thank you – Jijo John Jan 31 '22 at 09:56
  • That's slightly strange, since neither `!` nor `$` will cause trouble in an unquoted variable reference (unless you changed `IFS`, in which case change it back!). Normally, it's whitespace and/or filename wildcard characters that cause trouble in unquoted variable references. But double-quoting is almost always a good idea, and if that solved it, then yay! – Gordon Davisson Jan 31 '22 at 17:29

1 Answers1

0

your answer is using a pair of single quotes.

for example:

echo '!c$674'

the output is :

!c$674

now you need to set password vairable with single quotes.

rezshar
  • 570
  • 1
  • 6
  • 20
  • Thanks @rezshar. let me try this way as well. the solution worked for me is after modifying to "${USER}:${PASS}" instead of ${USER}:${PASS}. – Jijo John Jan 31 '22 at 09:58