I cant use my variables in the next autostart


@y=`cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2`

@chromium-browser --incognito $x$y

the y variable get the serial number

When chromium opens I get %24x%24y in urll browser. What I want is https://mypage.com/#myserialnumber .

Edit 20/03/2020

First I created the file

pi@raspberrypi:~ $ touch vars.sh

Then change the file

pi@raspberrypi:~ $ nano vars.sh

y=`cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2`

I change the autostart to this

@source ~/.vars.sh
@chromium-browser --incognito $f

but the result is the same %24f in the urll browser


The autostart file does not work like that.

Instead each command runs under its own subshell simultaneously. Therefore, your chromium command doesn't know those variables even exist.

To fix:

Put those 3 commands in a bash script (*.sh) file, make it executable, and put the path to the script in your autostart file.

Example script at /home/pi/Desktop/myscript.sh:

y="$(cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2)"
@chromium-browser --incognito $x$y

To make executable, run chmod +x /home/pi/Desktop/myscript.sh in a terminal. To run on boot, put @/home/pi/Desktop/myscript.sh in the autostart file.

  • Maybe the answer is to obvious but Im totally new and everything I know is from google. I edit the question could you give me more advice please. – Affj Mar 20 '20 at 16:51
  • That won't work either. You have to put all 3 commands in your .sh file. INCLUDING THE CHROMIUM LINE. – Botspot Mar 20 '20 at 20:06
  • I included to the bash script chromium-browser --incognito $f but now nothing opens – Affj Mar 20 '20 at 20:49
  • Run your script in the terminal. That way you can see any errors that show up. – Botspot Mar 20 '20 at 23:55
  • I ran the bash script in terminal like this source vars.sh and works perfect now I only need that autostart run the code. I think the problem is in autostart @source ~/.vars.sh I created the autostart with the command sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart – Affj Mar 21 '20 at 1:41

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.