What does the line $my_str="Password" indicate in a Bash script, and what is the common cause of the error described by a senior tester?

Prepare for the Penetration Testing and Vulnerability Analysis Test with a range of challenging questions. Study with multiple choice format, hints, and detailed explanations to ace your next exam!

Multiple Choice

What does the line $my_str="Password" indicate in a Bash script, and what is the common cause of the error described by a senior tester?

Explanation:
In Bash, you declare a variable with NAME=value, without any spaces around the equals sign. The $ prefix is used only when you reference or expand the variable’s value, not when you declare it. So the correct form is my_str="Password". A senior tester’s common error is putting a dollar sign in front of the name, like $my_str="Password", which Bash treats as attempting to expand a value on the left side of an assignment and results in a syntax error. The double quotes around Password are fine and help preserve the string, the underscore in the name is valid, and the assignment operator is the correct one to use.

In Bash, you declare a variable with NAME=value, without any spaces around the equals sign. The $ prefix is used only when you reference or expand the variable’s value, not when you declare it. So the correct form is my_str="Password". A senior tester’s common error is putting a dollar sign in front of the name, like $my_str="Password", which Bash treats as attempting to expand a value on the left side of an assignment and results in a syntax error. The double quotes around Password are fine and help preserve the string, the underscore in the name is valid, and the assignment operator is the correct one to use.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy