使用'here”语句时,必须确保语句不会在函数内部运行。可以将监控函数分解为多个行,'here”语句直接置于函数外部的行之间,例如:
#!/bin/bash
function monitoring { # Function code }
{ cat <<'EOF' >&7 Monitoring started... EOF monitoring cat <<'EOF' >&7 Monitoring stopped. EOF } 7>&1
在此示例中,将监控函数拆解为了多个行,并'here”语句放置于函数外部的行之间。这样可以确保语句不会在函数内部运行,从而解决了'here”语句在监控函数中无法使用的问题。