CompTIA PenTest+ 2025 – 400 Free Practice Questions to Pass the Exam

Question: 1 / 400

In Bash, how are variables assigned?

my_str = "Hello, World!"

my_str:= "Hello, World!"

my_str === "Hello, World!"

my_str="Hello, World!"

In Bash, variables are assigned using the syntax where you specify the variable name followed immediately by an equal sign, without spaces, and then the value you want to assign. The correct format is `my_str="Hello, World!"`, which adheres to the rules of shell scripting that require no whitespace around the equal sign. This method makes the variable `my_str` hold the string "Hello, World!", which can then be utilized later in the script.

The other choices provide incorrect formats for variable assignment in Bash. Using spaces around the equal sign, as in the first choice, is not allowed and will result in an error. The second choice employs the wrong operator (`:=`), which is not valid in Bash for simple variable assignments. The third choice utilizes a triple equals sign (`===`), which is relevant in other programming languages but does not apply to variable assignments in Bash.

Get further explanation with Examzify DeepDiveBeta
Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy