0

I have a loop function in .bash_aliases to help me quickly monitor certain commands.

loop()
{
 while sleep 1;
  do $@;
 done
}

However, I cannot get this command to work:

# loop mysql vb -e 'select count(*) from postparsed;'

# loop mysql vb -e "select count(*) from postparsed;"

# loop "mysql vb -e 'select count(*) from postparsed;'"

All of these return a mysql invalid command line parameter error, because the entire string isn't getting passed to mysql.

mysql Ver 15.1 Distrib 10.4.12-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Usage: mysql [OPTIONS] [database]

I also confirmed with this:

loop echo mysql vb -e 'select count(*) from postparsed;'

mysql vb -e select count(*) from postparsed;

mysql vb -e select count(*) from postparsed;

Looks fine to me.

What am I missing? Why is the loop() function not processing my mysql command correctly?

Thank you

Community
  • 1
  • 1
ctrlbrk
  • 1,174
  • 2
  • 17
  • 27

1 Answers1

1

The shell interprets the quotes, so the script doesn't see what you entered at the command line. What you need is

loop mysql vb -e 'select count(*) from postparsed;'

At the same time, though, you need to change the script to keep the whole SQL command as one word. Just double quote the parameter array to achieve this:

do "$@"
choroba
  • 231,213
  • 25
  • 204
  • 289