I have my wp-cli.yml configured with a working ssh connection.

If I wp db query "CHECK TABLE $(wp db tables | paste -s -d, -);" and run locally it works just fine.

On the other hand, if I wp @prod db query "CHECK TABLE $(wp db tables | paste -s -d, -);"

I get "too many positional arguments"

if I wp @prod option get home - it works fine.

This leads me to conclude that the escaping of the remote command is causing the error - no amount of testing has revealed the "right" combination of single/double-quotes to get the command to the remote server.


  • 2
    are you sure both your local and remote environments are using the same shell? How do you know which command has the issue when there are at least 3 commands nested on the same line? Have you tested the inner shell inside $() works as expected with the desired output? What are you actually trying to do? This looks like a classic X Y problem where you asked how to fix your solution rather than how to solve your problem
    – Tom J Nowell
    Jan 19 at 16:13
  • Looks like a sub-shell problem. Maybe can be fixed by more escaping. What does wp @prod db query "CHECK TABLE ${wp db tables | paste -s -d, -};" or wp @prod db query "CHECK TABLE {$(wp db tables | paste -s -d, -)};" do?
    – leymannx
    Jan 19 at 21:49
  • Indeed @TomJNowell - I wrote this with an example that illustrated my issue. I am using different shells (zsh locally, bash on the remote). Ultimately - I am trying to use wp-cli to run a db query on the remote - unsuccessfully. This is an example I borrowed from the wp-cli examples - i.e unlikely that it was a user-induced error.
    – Tom Ransom
    Jan 20 at 14:13
  • @leymannx thanks for the input - the first above returns "bad substitution" from zsh & the second runs on the remote and returns Error: Too many positional arguments: TABLE wp_blog_aliases wp_blog_aliasmeta wp_blogmeta wp_blogs wp_commentmeta wp_comments wp_links wp_options wp_postmeta wp_posts wp_registration_log wp_signups wp_site wp_sitemeta wp_term_relationships wp_term_taxonomy wp_termmeta wp_terms wp_usermeta wp_users
    – Tom Ransom
    Jan 20 at 14:17
  • 1
    @TomJNowell - ah that was just the mental clue I needed to sort this out. I'll post a working example as soon as I get it working!
    – Tom Ransom
    Jan 22 at 13:57


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.