3

I am running a bash script that calls mysql. The password ist not correctly transmitted, I guess I have to escape some special chars, like the hash or the dollar sign?

#!/bin/bash

USER=myuser
PASS="#mypass$"

# ... call mysql

2 Answers 2

2

Using "..." is already the correct thing to do, but the $ needs to be escaped (\$) if it isn't followed by an "invalid" character. However you also need to make sure to always have the variable in quotation marks as well, as in:

somecommand -p "$PASS"
Sign up to request clarification or add additional context in comments.

1 Comment

Using "..." is already the correct thing to do I'm confused. Is "# ..." a special sequence in bash?
1

Try to use "\" before the character that you are trying to escape.

#!/bin/bash

USER=myuser
PASS="#mypass\$"

# ... call mysql

1 Comment

@mit: You could also just change to single quotes which prevents the expansion of the contents. PASS='#mypass$' Beware the security implications of passing passwords on the command line.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.