zsh /home/kaffe/.aliases:13: `|' 附近的解析错误
zsh /home/kaffe/.aliases:13: parse error near `|'
我写了一个巨大的单行作为工具来检查一些我想分解和评论的工作日志,所以我以后可以理解它。当我完成分解后,我遇到了这个错误:
/home/kaffe/.aliases:13: parse error near `|'
11 mlog () {
12 cat /home/kaffe/progs/muse/nxaa* \ # Look in all muse logs
13 | grep "$(date +'%Y-%m-%d')\|$(date --date '-1 days' +'%Y-%m-%d')" \ # Dynamic search for date - today and yesterday
14 | sed -e 's/ com.*(): / /; \ # Start sed, remove irrelevant information
15 s/;/ /;s/;/ /; \ # Remove first two instances of semi-colon in every line
16 s/, severity../ /; \ # Globally remove mention of severity level
17 s/.*New alarm:/ New: &/g; \ # If "New alarm:" exists, add "New:" to beginning of line
18 s/ New alarm: / /g1; \ # Globally remove "New alarm:" from line
19 s/.*Alarm cleared:/Cleared: &/g; \ # If "Alarm cleared:" exists, add "Cleared:" to beginning
20 s/ Alarm cleared: / /g1; \ # Globally remove "Alarm cleared:" from line
21 s/.*Alarm changed:/Changed: &/g; \ # If "Alarm changed:" exists, add "Changed:" to beginning
22 s/ Alarm changed: / /g1' \ # Globally remove "Alarm changed:" from line
23 -e ''/ New:/s//$(printf "3[31mNew:3[0m")/g'' \ # Color "New:" red
24 -e ''/Cleared:/s//$(printf "3[32mCleared:3[0m")/g'' \ # Color "Cleared:" green
25 -e ''/Changed:/s//$(printf "3[33mChanged:3[0m")/g'' \ # Color "Changed:" yellow
26 | sort -k1.24 \ # Sort from 14th character (date)
27 | egrep -i # Insert custom search pattern, allow regexp, case insensitive
28 }
虽然该功能似乎按预期工作。我只是想了解为什么会出现错误,而我糟糕的 zsh-fu 限制我弄清楚它。了解导致这种情况的原因可能会对我未来的 zsh 努力有所帮助。
提前感谢您的贡献。
OS 和 zsh 版本:
$ uname -a
Linux kaffe-noc 3.2.0-4-amd64 #1 SMP Debian 3.2.68-1+deb7u3 x86_64 GNU/Linux
$ zsh --version
zsh 4.3.17 (x86_64-unknown-linux-gnu)
你在真实代码中有这些注释吗?
在 \
之后不能有任何内容,只能有一个换行符。
man bash
A non-quoted backslash () is the escape character. It preserves
the literal value of the next character that follows, with the
exception of . If a \ pair appears, and the
backslash is not itself quoted, the \ is treated as a line
continuation (that is, it is removed from the input stream and
effectively ignored).
我写了一个巨大的单行作为工具来检查一些我想分解和评论的工作日志,所以我以后可以理解它。当我完成分解后,我遇到了这个错误:
/home/kaffe/.aliases:13: parse error near `|'
11 mlog () {
12 cat /home/kaffe/progs/muse/nxaa* \ # Look in all muse logs
13 | grep "$(date +'%Y-%m-%d')\|$(date --date '-1 days' +'%Y-%m-%d')" \ # Dynamic search for date - today and yesterday
14 | sed -e 's/ com.*(): / /; \ # Start sed, remove irrelevant information
15 s/;/ /;s/;/ /; \ # Remove first two instances of semi-colon in every line
16 s/, severity../ /; \ # Globally remove mention of severity level
17 s/.*New alarm:/ New: &/g; \ # If "New alarm:" exists, add "New:" to beginning of line
18 s/ New alarm: / /g1; \ # Globally remove "New alarm:" from line
19 s/.*Alarm cleared:/Cleared: &/g; \ # If "Alarm cleared:" exists, add "Cleared:" to beginning
20 s/ Alarm cleared: / /g1; \ # Globally remove "Alarm cleared:" from line
21 s/.*Alarm changed:/Changed: &/g; \ # If "Alarm changed:" exists, add "Changed:" to beginning
22 s/ Alarm changed: / /g1' \ # Globally remove "Alarm changed:" from line
23 -e ''/ New:/s//$(printf "3[31mNew:3[0m")/g'' \ # Color "New:" red
24 -e ''/Cleared:/s//$(printf "3[32mCleared:3[0m")/g'' \ # Color "Cleared:" green
25 -e ''/Changed:/s//$(printf "3[33mChanged:3[0m")/g'' \ # Color "Changed:" yellow
26 | sort -k1.24 \ # Sort from 14th character (date)
27 | egrep -i # Insert custom search pattern, allow regexp, case insensitive
28 }
虽然该功能似乎按预期工作。我只是想了解为什么会出现错误,而我糟糕的 zsh-fu 限制我弄清楚它。了解导致这种情况的原因可能会对我未来的 zsh 努力有所帮助。
提前感谢您的贡献。
OS 和 zsh 版本:
$ uname -a
Linux kaffe-noc 3.2.0-4-amd64 #1 SMP Debian 3.2.68-1+deb7u3 x86_64 GNU/Linux
$ zsh --version
zsh 4.3.17 (x86_64-unknown-linux-gnu)
你在真实代码中有这些注释吗?
在 \
之后不能有任何内容,只能有一个换行符。
man bash
A non-quoted backslash () is the escape character. It preserves the literal value of the next character that follows, with the exception of . If a \ pair appears, and the backslash is not itself quoted, the \ is treated as a line continuation (that is, it is removed from the input stream and effectively ignored).