小编Ray*_*ndo的帖子

如何根据bash中的变量有条件地将输出重定向到文件

我正在尝试使用 eval 命令来评估评论——我不确定这是否是正确的方法。例子:

i=??(我在这里想要的是#, 评论之后的内容,或空白)

somecommand arg1 arg2 $(eval $i) >> file

因此,根据$i价值,它必须是:

somecommand arg1 arg2 # >> file 从“不打印到文件”开始

或者

somecommand arg1 arg2 >> file 从“打印到文件”开始

一个更清晰的示例脚本:

i=true

somecommand arg1 arg2 >> file1
[some code]
somecommand arg1 arg2 >> file2
[some code]
somecommand arg1 arg2 >> file3
[some code]
And so on...
Run Code Online (Sandbox Code Playgroud)

我希望它只有在$i它为真时才将输出打印到文件中;或者,正如我最初尝试的那样,eval将 $i 设为注释并注释“输出到文件”的一段代码。

我问是因为我认为有一种比做这样的事情更优雅的方式:

if $i
then
   somecommand arg1 arg2 >> file3
else
   somecommand arg1 arg2
fi
Run Code Online (Sandbox Code Playgroud)

bash eval

4
推荐指数
1
解决办法
621
查看次数

为什么我使用 curl 获得二进制输出

不确定是否可以共享我试图获取其来源的网站,但我认为有必要进行更好的解释。如果不是提前,我深表歉意

命令: curl -k -L -s https://www.mi.com

由于出现以下错误,由于某种原因,输出是二进制数据

Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.
Run Code Online (Sandbox Code Playgroud)

如何阅读页面 HTML 源代码?谢谢!

binary curl

2
推荐指数
2
解决办法
6728
查看次数

标签 统计

bash ×1

binary ×1

curl ×1

eval ×1