Why does the error not appear when there is space before and after "=" in the Bash script?

Asked 2 years ago, Updated 2 years ago, 93 views

inadvertently

when replacing with a Bash script
foo="bar"

I wrote = with spaces before and after oo, but the foo was not replaced and the error did not occur.

Using the same description on an interactive bash shell

bash:foo:command not found

It's an error, but why don't you throw up the error in the script?

bash

2022-09-30 11:33

2 Answers

I wrote the variable name foo in the question.

In an environment where there were no errors, the variable name used the name basename as the command. The command not found error did not appear, and it seemed to be treated as a variable with a blank string after the substitute line.

I have posted an answer to close the question, although it contains information that was not included in the question.


2022-09-30 11:33

I don't need any space when I replace it with bash.Run line by line, so if you write foo="bar", you execute the foot command, where = and "bar" are arguments.Without the foo command, the command not found error appears.
It looks like ls-la./.If ls is changed to sdfsdfsdf, sdfsdf-la. / Same, command not found error should appear.


2022-09-30 11:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.