View Full Version : [SOLVED] can't get alias clear_atq="for i in `atq | awk '{print $1}'`;do atrm $i;done" to work

October 6th, 2013, 01:05 PM
I am trying to make an alias that will clear out all of the queue of the "at" commands.
This works just fine when I post it into a terminal:

for i in `atq | awk '{print $1}'`;do atrm $i;done

but when I try to make an alias out of it:

alias clear_atq="for i in `atq | awk '{print $1}'`;do atrm $i;done"

I get this error when I type "clear_atq" in the terminal:

bash: syntax error near unexpected token `460'
"460" being one of the "at" queue numbers.

I think it has something to do with the number of
" ' `
that are in the alias, but don't know.


Lars Noodén
October 6th, 2013, 01:28 PM
Here's what I got from the above:

alias clear_atq='for i in $(atq | awk "{print \$1}");do atrm $i;done'

This is complicated because it is intepreted in two parts. First as it is made an alias. Then again as the alias is run.

October 6th, 2013, 01:35 PM
don't bother with alias and write a function or a script instead. Aliases are for really simple stuff and you are trying to fit a square peg into a round hole.

clear_atq() { for i in $( atq | awk '{ print $1 }' ); do atrm $i; done; }

October 6th, 2013, 06:18 PM
Thanks guys,
The alias works and I am going to look into making a script too.