I'm trying to make an alias to quickly compile and upload Arduino sketches. I started by adding the location and fqbn of my arduino as shell variables, but that slowed down each shell start up, so I decided to add a check instead, and only export the variables if they aren't already exported. Now, it seems that the script isn't accessing the variables even though I can echo them after the function for exporting them has run. The error from the shell seems to indicate that the variables are still empty when they are called by the script, even if I run it a second time in the same shell. Here's the functions and alias which I'm referring to:
function dweeno() {
export DWEENOFQBN="$(arduino-cli board list | grep USB | awk '{print $(NF-1)}')"
export DWEENOLOC="$(arduino-cli board list | grep USB | awk '{print $1}')"
}
function dweenocheck() {
if [ -z $DWEENOFQBN ]; then
dweeno
fi
}
alias acu="dweenocheck && arduino-cli compile --fqbn $DWEENOFQBN $1 && arduino-cli upload -p $DWEENOLOC --fqbn $DWEENOFQBN $1"
$DWEENOFQBNwould have been used in the definition, rather than the current value, and the parameter would expand each time the alias is expanded. That said, you still want to use a function instead, because$1would be expanded using the current positional argument, not whatever argument followed the alias on the command line.