Reputation: 464
I wrote a massive one-liner as a tool to check some logs at work which I wanted to break up and comment, so I could understand it at a later date. When I was done breaking it all up, I bumped into this error:
/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 "\033[31mNew:\033[0m")/g'' \ # Color "New:" red
24 -e ''/Cleared:/s//$(printf "\033[32mCleared:\033[0m")/g'' \ # Color "Cleared:" green
25 -e ''/Changed:/s//$(printf "\033[33mChanged:\033[0m")/g'' \ # Color "Changed:" yellow
26 | sort -k1.24 \ # Sort from 14th character (date)
27 | egrep -i $1 # Insert custom search pattern, allow regexp, case insensitive
28 }
The function seems to work as intended, though. I just wish to understand why there is an error and my abysmal zsh-fu restricts me from figuring it out. Knowing what causes this would probably help me in future zsh endeavors.
Thanks in advance for any contribution.
OS and zsh versions:
$ 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)
Upvotes: 0
Views: 402
Reputation:
Do you have those comments in real code ?
You can not have anything after \
but a newline for line continuation.
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).
Upvotes: 1