0

I am trying to run a bash script and set the variables in one command. Is this possible?

bash wp.sh dbname="hello",dbuser="admin"

It's not working for me, and I can't seem to find any guidance on this. Thanks in advance for your help!

  • Similar, but not exact duplicate: https://stackoverflow.com/questions/7128542/how-to-set-an-environment-variable-only-for-the-duration-of-the-script – Benjamin W. Nov 18 '17 at 04:34

1 Answers1

2

To set environment variables that will be inherited by the script process, put the assignments at the beginning:

dbname="hello" dbuser="admin" bash wp.sh
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Thank you so much! That did it. As soon as it lets me mark this as the correct answer (in ~10 minutes), I will. Much appreciated! :) – Bradly Hale Nov 18 '17 at 00:59
  • 2
    Your other option is to process the values as command line arguments, but that would take modifying the script to properly accept them. Sometimes is just the simple things that help. – David C. Rankin Nov 18 '17 at 01:12