我有一个 test.sh
通过文本文件 awks 的文件 test.bed
:
1 31 431
1 14 1234
1 54 134
2 435 314
2 314 414
和
while read line;do
echo $line
# ... more code ... #
done < <(awk -F '\t' '$1 == 1 {print $0}' test.bed )
使用
bash test.sh
运行它有效,但使用 sh test.sh
它给出了语法错误。我怎么能用 sh
做上述事情而不是 bash
?它给出的错误是
test.sh: line 5: syntax error near unexpected token `<'
test.sh: line 5: `done < <(awk -F '\t' '$1 == 1 {print $0}' test.bed )'
最佳答案
Process Substitution是 bash
扩展 - 未由 POSIX
指定.这是sh
兼容的..
#!/bin/sh
awk -F '\t' '$1 == 1 {print $0}' test.bed | while read line; do
echo $line
# ... more code ... #
done
关于bash - 如何使用 sh 迭代 awk 的每个输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36793460/