【问题标题】:How to fix boxes coming in filename?如何修复文件名中的框?
【发布时间】:2021-07-27 02:32:28
【问题描述】:

我正在制作一个脚本,它将每个 Linux 命令的手册页放入文件中。

man.sh:

while :
do
    echo -n "command:"
    read command
    man "$command" > op/"$command".txt
done

commands.txt

运行.sh:

awk '{i=1; while(i<=NF){ print $((i++)); system("clear") }}' commands.txt | bash man.sh

当我运行bash run.sh 时,它正在制作文件,但文件名称不正确:

它们里面什么都没有:

我该如何解决这个问题?

【问题讨论】:

  • "command" 是 bash 内置的名称,因此不是一个好的变量名。
  • 我认为您应该删除将控制字符发送到标准输出的system("clear")
  • 您是否知道联机帮助页已经是本地磁盘上的纯文本文件?你可以在这里使用cp
  • @jordanm 他们经常是 gzip。
  • 我跑了 whereis man 并得到了 /usr/bin/man /usr/local/man /usr/share/man 并检查了它们,但它们都没有手册页。

标签: linux bash loops awk output


【解决方案1】:

无论您尝试做什么,都从减少无限读取开始:

while read -r command1;
do
    echo -n "command:"
    read command1
    man "$command1" > op/"$command".txt
done

【讨论】:

    【解决方案2】:

    我认为你对整个事情进行了过度设计:

    while IFS= read -r cmd; do man "$cmd" > op/"$cmd".txt; done <"commands.txt"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-01
      • 1970-01-01
      • 2017-04-06
      相关资源
      最近更新 更多