2

I want to run sql from the command line:

mysql -u user -p database -e "INSERT INTO table VALUES ( NULL, [hash] , NOW(), 0);

I want to replace [hash] with the response of another command line command:

date +%s | md5sum

Is there a way to make that substitution?

1 Answer 1

2

Yes, assuming you are using bash (and closing the open quote) -

mysql -u user -p database \
  -e "INSERT INTO table VALUES ( NULL, $(date +%s | md5sum) , NOW(), 0);"
4
  • Thanks, I was trying to do it only on the command line, putting it into a shell script was the right thing to do. Apr 4, 2014 at 19:22
  • The above will work on the command line too; assuming your shell is bash. Apr 4, 2014 at 19:23
  • Thanks, I see, yes that works on the command line as well Apr 4, 2014 at 19:31
  • Instead of $() you can wrap the command in backticks and it will work in any shell. It's also one less character to type ;)
    – psusi
    Apr 4, 2014 at 21:51

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.