Reputation: 1
I wanted to create an alias in terminal (OSX) for this command:
cal -y | awk -v month="`date +%m`" -v day="`date +%e` " '{m=int((NR-3)/8)*3+1; for (i=0;i<3;i++) {t[i]=substr($0,1+i*22,20) " "; if (m+i==month) sub(day,"\033[0;31m&\033[0m",t[i]);} print t[0],t[1],t[2];}'
The command works perfectly fine when I just run it, but when I try to create an alias for it it gives me this error:
Syntax Error near unexpected token `('
My code for creating the alias was:
alias caly='cal -y | awk -v month="`date +%m`" -v day="`date +%e` " '{m=int((NR-3)/8)*3+1; for (i=0;i<3;i++) {t[i]=substr($0,1+i*22,20) " "; if (m+i==month) sub(day,"\033[0;31m&\033[0m",t[i]);} print t[0],t[1],t[2];}''
I also tried to use escape sequences, as the error might be the fact that there are already single quotations in the command before I put the single quotations around the whole line. This is the second piece of code I tried (which gave me the same error):
alias caly='cal -y | awk -v month="`date +%m`" -v day="`date +%e` " \'{m=int((NR-3)/8)*3+1; for (i=0;i<3;i++) {t[i]=substr($0,1+i*22,20) " "; if (m+i==month) sub(day,"\033[0;31m&\033[0m",t[i]);} print t[0],t[1],t[2];}\''
Does anyone know how I can fix this error? I'm pretty new to terminal, so any advice is appreciated!
Upvotes: 0
Views: 158
Reputation: 3201
The error is because the command string you're passing to alias
, which is enclosed by single quotes, itself also contains single quotes.
I doubt there is a simple solution that still uses alias
. I looks like you're pushing the expression passed to alias
a bit too far. Consider putting your code in a shell script instead, and adding that script to a directory that is in your search path.
Upvotes: 0