less:过滤掉作为命令行参数传递的模式 + 通过 bash 函数跟踪文件

less: filter out pattern passed as command line argument + follow file via bash function

我正在尝试创建一个 bash 函数,该函数将使用 less 应用模式并使用传递给该函数的参数跟随文件

my_less_function() {
        if [ -z "" ]
        then
                # if no arg
                less +F /var/log/my.log
        else
                # else, filter out the arg
                less +$'&!''\nF' /var/log/my.log
        fi
}

我的问题是我无法在 else 块中正确替换 arg

my_less_function MY_VALUE 在 less

中显示 Non-match &/MY_VALUE\nF

它看起来像是在连接参数和 \nF,但是 \nF 应该触发跟随命令而不是被解释为参数的一部分

有什么想法吗?

错误:less +$'&!''\nF' /var/log/my.log


对:less +$'&!'$'\nF' /var/log/my.log