0

I made a bash script to open a certain webpage after my Pi 2 has booted. To do so, I use Bash to read a file on my system containing an ID, and append it to an existing URL. This full URL then gets opened in a kiosk mode. The idea is that I can easily clone my SD card and only change 1 file to show a different page on different PIs, instead of changing it in the bash script.

When I run this script from the terminal, everything works fine. The file gets read, the url appended, and the right page is shown. However when it gets run from boot, the browser gets opened but the url without the appended ID gets shown.

What might cause the script from not reading the file on boot, but reading it fine from the terminal?

The script basically looks like this:

#!/bin/bash
PICONTENT=$(<pi_id) #my file with the id
echo "The id is $PICONTENT"
URL="myurl.com/$PICONTENT"
kweb $URL
exit
  • I'm presuming pi_id is an absolute path... – goldilocks Feb 18 '15 at 14:07
  • pi_id was actually a relative path. I made sure to change it to an absolute path now. I'll test this out and report back. – Sander van't Veer Feb 18 '15 at 14:20
  • @goldilocks Having tried an absolute path, the result stays the same. I modified my script so the browser starts in a normal window so I can see the URL, and can confirm the ID is not loaded from the file upon boot. Upon running the .sh file myself everything works fine. – Sander van't Veer Feb 18 '15 at 15:05
2

Use cat instead of < because your script is running with sh not bash.

  • What about the #!/bin/bash at the top of the script? – goldilocks Mar 1 '15 at 14:30
  • That can be ignored sometimes, if you want to insure bash is used, call your script with bash script.sh – user1133275 Mar 1 '15 at 14:48
  • @user1133275 Under what circumstances can the #! directive be ignored? – Bex Mar 1 '15 at 14:56
  • 2
    @Bex If the script is executed, e.g., sh script.sh, the shebang line is ignored or treated as a command "not found". On raspbian /bin/sh is a link to /bin/dash (not bash), which won't do $(<somefile); the variable will be empty. This is certainly worth a try; the OP does not say how it is executed but if it's via a dedicated init script init may execute it with sh. – goldilocks Mar 1 '15 at 15:01
  • I tried editing your answer - the back-ticks are not being displayed (but I see they are present in your source) - I couldn't get them to show up either. I'll log a post on meta – monojohnny Mar 1 '15 at 15:54

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.