bash - Bash shell 中的错误定界符

标签 bash

我正在尝试迭代几行 bash 脚本并回显所有非注释行。

在我的循环中,我有以下命令:

echo $line | cut -d" #" -f1

但是解释器向我抛出以下错误:

cut: bad delimiter

我做错了什么?

最佳答案

如评论中所述,cut-d 参数只需要一个字符。尝试使用 nawk 作为示例:

echo $line | nawk 'BEGIN {FS=" #" } ; { print $1 }'

或者只打印不以“#”开头的行,使用grep:

grep -v " #" <file>

或者只打印以散列开头的行,或者只打印空格和散列,我会使用 Perl:

perl -n -e 'unless (/(\S+)*#/) {print}' <file>

关于bash - Bash shell 中的错误定界符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25319492/

相关文章:

bash - 在 bash 中使用 "exit ${?}"是否正确?

javascript - 使用 Electron 调用 app.quit() 函数的 HTML 按钮

bash - "unable to get local issuer certificate"在 vagrant up 期间,即使在 vagrant box add --insecure 之后

Bash:是否可以通过评估命令为单个子进程设置环境变量?

linux - 文件中的 awk 命令在循环中执行时出错

linux - 在 Bash 中正确引用 : Attach numbers stored in i to a

linux - xargs bash -c 意外标记

python - <back space> 在 shell 中的 python 和 ipython 中不起作用

linux - 如何在 bash 中组合 "lsof -i :port"和 "kill pid"

bash - 从Shell脚本将结果值从Docker容器中的测试返回到Jenkins CI