且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如果没有空间,为什么等于运算符不起作用?

更新时间:2023-11-13 15:51:28

test(或[ expr ])是内置函数.像bash中的所有函数一样,您将其参数作为空格分隔的单词传递.

test (or [ expr ]) is a builtin function. Like all functions in bash, you pass it's arguments as whitespace separated words.

bash内置手册页指出:每个运算符和操作数必须是一个单独的参数."

As the man page for bash builtins states: "Each operator and operand must be a separate argument."

这只是bash和大多数其他Unix shell的工作方式.

It's just the way bash and most other Unix shells work.

变量分配是不同的.

在bash中,变量分配具有以下语法:name=[value].您不能在=周围放置未加引号的空格,因为bash不会将其解释为您想要的分配. bash将大多数单词列表视为带有参数的命令.

In bash a variable assignment has the syntax: name=[value]. You cannot put unquoted spaces around the = because bash would not interpret this as the assignment you intend. bash treats most lists of words as a command with parameters.

例如

# call the command or function 'abc' with '=def' as argument
abc =def

# call 'def' with the variable 'abc' set to the empty string
abc= def

# call 'ghi' with 'abc' set to 'def'
abc=def ghi

# set 'abc' to 'def ghi'
abc="def ghi"