Results 1 to 4 of 4

Thread: can't get alias clear_atq="for i in `atq | awk '{print $1}'`;do atrm $i;done" to work

  1. #1
    Join Date
    Jul 2013
    Beans
    171

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

    hi,
    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:
    Code:
    for i in `atq | awk '{print $1}'`;do atrm $i;done
    but when I try to make an alias out of it:
    Code:
    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:
    Code:
    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.

    Thanks

  2. #2
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: can't get alias clear_atq="for i in `atq | awk '{print $1}'`;do atrm $i;done" to

    Here's what I got from the above:

    Code:
    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.

  3. #3
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: can't get alias clear_atq="for i in `atq | awk '{print $1}'`;do atrm $i;done" to

    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.
    function:
    Code:
    clear_atq() { for i in $( atq | awk '{ print $1 }' ); do atrm $i; done; }
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  4. #4
    Join Date
    Jul 2013
    Beans
    171

    Re: can't get alias clear_atq="for i in `atq | awk '{print $1}'`;do atrm $i;done" to

    Thanks guys,
    The alias works and I am going to look into making a script too.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •