我正在处理大变量并加速我的脚本我想在不使用echo / printf的情况下awk或grep变量 我尝试过的: awk "/test/ {for(i=1; i=100; i++) {getline; print}}" "$var"awk: fatal: cannot open file `$var content' for reading (
我尝试过的:
awk "/test/ {for(i=1; i<=100; i++) {getline; print}}" "$var" awk: fatal: cannot open file `<<$var content>>' for reading (No such file or directory) grep -A 100 test "$var" grep: `<<$var content>>': No such file or directory在bash中,您可以使用单行heredoc从变量重定向到stdin:
awk "/test/ {for(i=1; i<=100; i++) {getline; print}}" <<< "$var"