相关疑难解决方法(0)

为什么 printf 比 echo 好?

我听说printfecho. 根据我的经验,我只能回忆起一个我不得不使用的实例,printf因为它echo无法将一些文本输入到 RHEL 5.8 上的某个程序中,但printf确实如此。但显然,还有其他差异,我想询问它们是什么以及是否有特定情况下何时使用一种与另一种。

echo text-processing printf

635
推荐指数
4
解决办法
27万
查看次数

理解“IFS= read -r line”

我显然明白可以为内部字段分隔符变量添加值。例如:

$ IFS=blah
$ echo "$IFS"
blah
$ 
Run Code Online (Sandbox Code Playgroud)

我也明白这read -r line会将数据保存stdin到名为的变量line

$ read -r line <<< blah
$ echo "$line"
blah
$ 
Run Code Online (Sandbox Code Playgroud)

但是,命令如何分配变量值?它是否首先存储来自stdinto 变量的数据line,然后赋予lineto 的值IFS

bash shell-script

94
推荐指数
3
解决办法
10万
查看次数

在不使用引号的情况下在 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
查看次数

隐藏命令的输入

更新为原始不清楚。

我正在计算机上设置 postfix 以使用我的电子邮件的 SMTP。

我不想以纯文本形式输入我的凭据,尤其是在公开输入时。

是否可以让 bash 不显示我对一两个命令的输入?

示例:我正在输入一系列命令,然后我想将用户名和密码回显到配置文件中。

我想快速进入我的输入不显示在屏幕上的模式,然后轻松地离开该模式ctl+c.

bash password

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