草庐IT

linux - 为什么 du 或 echo 流水线不起作用?

我正在尝试对当前目录中的每个目录使用du命令。所以我正在尝试使用这样的代码:ls|du-sb但它没有按预期工作。它仅输出当前“.”的大小。目录,仅此而已。echo也是一样ls|echo输出空行。为什么会这样? 最佳答案 使用管道将第一个命令的输出(stdout)发送到子进程(第二个命令)的stdin(输入)。您提到的命令不会对stdin进行任何输入。例如,这可以与cat一起工作(并且通过工作,我的意思是像cat一样工作,不带参数运行,只传递你给它的输入):ls|cat对于您的应用程序,这就是xargs发挥作用的地方。它接受管道输入并

linux - 为什么我必须输入 "\\\0"才能在zsh中创建一个字符串 "\0"?

>echo00>echo\00slu@dev:~>echo\\0slu@dev:~>echo"\\0"#echo\\\0slu@dev:~>echo"\\\0"\0slu@dev:~>bashExecuting.bashrc$echo"\0"\0$echo"\\0"\0$echo"\\\0"\\0我得说,bash的行为对我来说更有意义。更多详情:slu@dev:~>echo"0"|hexdump-C00000000300a|0.|00000002slu@dev:~>echo"\0"|hexdump-C00000000000a|..|00000002slu@dev:~>echo"\\0"

linux - 为什么我必须输入 "\\\0"才能在zsh中创建一个字符串 "\0"?

>echo00>echo\00slu@dev:~>echo\\0slu@dev:~>echo"\\0"#echo\\\0slu@dev:~>echo"\\\0"\0slu@dev:~>bashExecuting.bashrc$echo"\0"\0$echo"\\0"\0$echo"\\\0"\\0我得说,bash的行为对我来说更有意义。更多详情:slu@dev:~>echo"0"|hexdump-C00000000300a|0.|00000002slu@dev:~>echo"\0"|hexdump-C00000000000a|..|00000002slu@dev:~>echo"\\0"

linux - 将 stdout 和 stderr 恢复为默认值

在shell脚本中,我们可以使用exec命令将默认输入更改为文件,如下所示:exec1>outputfile但是,如果在同一个脚本中,如果我想将标准输出描述符“1”恢复为默认值(终端)。我们怎样才能做到这一点? 最佳答案 这个例子Example20-2.Redirectingstdoutusingexec#!/bin/bash#reassign-stdout.shLOGFILE=logfile.txtexec6>&1#Linkfiledescriptor#6withstdout.#Savesstdout.exec>$LOGFILE#

linux - 将 stdout 和 stderr 恢复为默认值

在shell脚本中,我们可以使用exec命令将默认输入更改为文件,如下所示:exec1>outputfile但是,如果在同一个脚本中,如果我想将标准输出描述符“1”恢复为默认值(终端)。我们怎样才能做到这一点? 最佳答案 这个例子Example20-2.Redirectingstdoutusingexec#!/bin/bash#reassign-stdout.shLOGFILE=logfile.txtexec6>&1#Linkfiledescriptor#6withstdout.#Savesstdout.exec>$LOGFILE#

linux - 当它被分成多行时如何避免 echo 中的空格

我有一个很长的字符串要用echo命令打印。通过这样做,我希望它完全缩进。我正在尝试这个,它运行良好echo"Thisisaverylongstring.An"\"ditisprintedinoneline"Output:Thisisaverylongstring.Anditisprintedinoneline但是当我尝试正确缩进时,因为echo语句也被缩进了。它增加了一个额外的空间。echo"Thisisaverylongstring.An"\"ditisprintedinoneline"Output:Thisisaverylongstring.Anditisprintedinonel

linux - 当它被分成多行时如何避免 echo 中的空格

我有一个很长的字符串要用echo命令打印。通过这样做,我希望它完全缩进。我正在尝试这个,它运行良好echo"Thisisaverylongstring.An"\"ditisprintedinoneline"Output:Thisisaverylongstring.Anditisprintedinoneline但是当我尝试正确缩进时,因为echo语句也被缩进了。它增加了一个额外的空间。echo"Thisisaverylongstring.An"\"ditisprintedinoneline"Output:Thisisaverylongstring.Anditisprintedinonel

linux - 使用 echo/linux 创建一个包含多行脚本的输出文件

尝试创建一个小脚本,能够在不进行任何更改的情况下从输出文件中的脚本中删除一部分,(按原样)源文件文本echo"yellow=`tputsetaf3`bel=`tputbel`red=`tputsetaf1`green=`tputsetaf2`reset=`tputsgr0echo"#${green}Installingpackages${reset}#"&&">>output.txt期望的输出:yellow=`tputsetaf3`bel=`tputbel`red=`tputsetaf1`green=`tputsetaf2`reset=`tputsgr0echo"#${green}In

linux - 使用 echo/linux 创建一个包含多行脚本的输出文件

尝试创建一个小脚本,能够在不进行任何更改的情况下从输出文件中的脚本中删除一部分,(按原样)源文件文本echo"yellow=`tputsetaf3`bel=`tputbel`red=`tputsetaf1`green=`tputsetaf2`reset=`tputsgr0echo"#${green}Installingpackages${reset}#"&&">>output.txt期望的输出:yellow=`tputsetaf3`bel=`tputbel`red=`tputsetaf1`green=`tputsetaf2`reset=`tputsgr0echo"#${green}In

linux - xargs 可以分隔参数吗?

echo"'param1''param2'"|xargs-n2-I@echo[@][@]此命令输出:[param1param2][param1param2]但是,我希望它输出:[param1][param2]有没有办法用xargs做到这一点?我计划将它与-L1一起使用,这样该解决方案将处理多行以及多个参数。 最佳答案 对于那些通过搜索找到这个的人来说,接受的答案对我不起作用。echo"'param1''param2'"|xargs-n1|xargs-I@echo\[@\]\[@\]产生:[param1][param1][param2