Getting variables from a bash script and use them in an Arduino code

Hi there,

I'm newbie here and I'm trying to make a project, in which I have some files with bash scripts (username and password variables), and I have an arduino code in which I want to use those external variables (username and password) like:
const char *username = ${USERNAME-EXTERNAL-VARIABLE};
const char *password= ${PASSWORD-EXTERNAL-VARIABLE};

Could anyone help me? Thank you so much!

Does your bash script send that data to the Arduino over a serial connection?

Is your Arduino program designed to receive that data?

It will be much easier to help if you give a full description of the project you are trying to create.

Using bash scripts with an Arduino can be troublesome because when the script opens the serial port it usually causes the Arduino to reset and the script does not know to wait until the reset process is complete.


At runtime? Not really possible, as Robin said.

At compile time... not really possible, either. The compiler is invoked pretty distantly from the shell...

At compile time, if you are using arduino-cli, you could have the bash script insert the username and password into the sketch ino file then invoke the compiler. Probably would be better to have the variable declarations for the username and password in a separate file and use an #include to include it into your code, similar to the way it is done in a lot of the wifi library examples.