小编Cal*_*aul的帖子

在不使用引号的情况下在 shell 中将一个变量分配给另一个变量有什么问题吗?

这个问题是关于一个变量的全部内容分配给另一个变量。

使用变量(发送至echo等)

赋值期间没有进行参数扩展

我的问题也仅与 POSIX shell 有关(此处未使用数组)。

error="You have an error in your input"

newVar="$error"
# vs.
newVar=$error
#         ?
#         ??This assignment is the question. It doesn't seem that quotes are
#           needed here in order to assign the entire contents of $error to
#           a new variable.

#                 ??(But quotes are required when they're used.)
#                 ?
printf "%s\n" "$error"
# => You have an error in your …
Run Code Online (Sandbox Code Playgroud)

shell posix quoting assignment

5
推荐指数
1
解决办法
2729
查看次数

标签 统计

assignment ×1

posix ×1

quoting ×1

shell ×1