Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9173781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:38:38+00:00 2026-06-17T16:38:38+00:00

Shell command inside MySQL shell returns value: mysql> \! echo 1 1 How to

  • 0

Shell command inside MySQL shell returns value:

mysql> \! echo 1
1

How to assign this result to MySQL variable? Like:

mysql> set @var = \! echo 1
1
    -> ;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ” at line 1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:38:40+00:00Added an answer on June 17, 2026 at 4:38 pm

    The problem is that SET is a server command, which changes the state of variables held on the server; whereas system (and its \! shorthand) is a client command, which forks a process on the client. Whilst it could be possible for the client to transmit the forked process’s exit code to the server for storage in a user variable, I don’t think the MySQL command line client offers this functionality.

    From mysql-5.5.29/client/mysql.cc:

    3958: static int
    3959: com_shell(String *buffer __attribute__((unused)),
    3960:           char *line __attribute__((unused)))
    3961: {
    3962:   char *shell_cmd;
    3963: 
    3964:   /* Skip space from line begin */
    3965:   while (my_isspace(charset_info, *line))
    3966:     line++;
    3967:   if (!(shell_cmd = strchr(line, ' ')))
    3968:   {
    3969:     put_info("Usage: \\! shell-command", INFO_ERROR);
    3970:     return -1;
    3971:   }
    3972:   /*
    3973:     The output of the shell command does not
    3974:     get directed to the pager or the outfile
    3975:   */
    3976:   if (system(shell_cmd) == -1)
    3977:   {
    3978:     put_info(strerror(errno), INFO_ERROR, errno);
    3979:     return -1;
    3980:   }
    3981:   return 0;
    3982: }
    

    Note in particular that the return value of the system(3) call is not stored anywhere; however the com_shell() function call will return -1 if the process exited with that code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the command history inside a shell script. It doesn't work
Which Windows Shell command will print a file content on the standard output (like
How can I execute a shell command, can be complicated like normal command in
Basically I want to execute a shell command inside a jailed process. When I
I have a problem updating a value of a variable in a shell script
I would like to automate the following svn command. Note this command produces the
I'm trying to populate a shell variable called $recipient which should contain a value
I am trying to run a simple shell command that runs and returns text
I use Yii command line inside web Root folder (C:\xampp\htdocs\myapps\cmd.exe). My command looks like
I am trying to access a shell variable inside a piped nawk. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.