MattZ40
Posts: 10
Joined: Tue Nov 20, 2018 5:10 pm

Bash: No such file or directory

Tue Nov 20, 2018 5:57 pm

Hopefully someone can offer some advice. I've struggled with this for a week and have made no progress so I'm appealing to the experts.
I'm trying to run a script called startframe.sh If I get to it via file manager, double click it, then click on Execute, it runs.
If I try to execute it in a terminal by typing "/frame/startframe.sh" I get "bash: /frame/startframe.sh: No such file or directory"
If I cd to the /frame directory and type "frame.sh" I get "frame.sh: command not found"
If I add sudo before the commands above, both return "command not found"

"file startframe.sh" returns
startframe.sh: POSIX shell script, ASCII text executable

"ldd startframe.sh" returns
not a dynamic executable

The script is:
#! /bin/sh
sleep 3; /usr/bin/feh --quiet --recursive --randomize -- full-screen --hide-pointer --slideshow-delay 5 /home/pi/frame/pictures

It has worked for several years until I ran into display hardware problems and needed to make changes to the script in order to troubleshoot the hardware. Couldn't recall or find how I was executing the script on boot and decided to reload raspbian and start over from scratch. I couldn't get the script to run on boot but along the way with updates/upgrades/etc the problem of not being able to run it in terminal started.

Hardware is RPi 2 mod B rev 1.1
Raspbian version = 9 (stretch)

Any advice would be appreciated

Andyroo
Posts: 4132
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Bash: No such file or directory

Tue Nov 20, 2018 7:22 pm

A couple of quick thoughts:

1) Why hashbang to sh and not bash? sh on the Pi is a symbolic link that points to dash on Stretch.
2) Do you have the execute flag set?
Need Pi spray - these things are breeding in my house...

DirkS
Posts: 9897
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Bash: No such file or directory

Tue Nov 20, 2018 7:29 pm

MattZ40 wrote:
Tue Nov 20, 2018 5:57 pm
If I try to execute it in a terminal by typing "/frame/startframe.sh" I get "bash: /frame/startframe.sh: No such file or directory"
If I cd to the /frame directory and type "frame.sh" I get "frame.sh: command not found"
If I add sudo before the commands above, both return "command not found"
From the code in the scripts I would say your script is not in directory /frame, but in /home/pi/frame

So to run it you need to use either of the following commands

Code: Select all

/home/pi/frame/startframe.sh
~/frame/startframe.sh

MattZ40
Posts: 10
Joined: Tue Nov 20, 2018 5:10 pm

Re: Bash: No such file or directory

Tue Nov 20, 2018 9:01 pm

Andyroo wrote:
Tue Nov 20, 2018 7:22 pm
A couple of quick thoughts:

1) Why hashbang to sh and not bash? sh on the Pi is a symbolic link that points to dash on Stretch.
2) Do you have the execute flag set?
1) No reason other than I've had it that way for over a decade. I switched it to bash and it does the same thing, although it also is working which I'll explain in my next reply below.
2) Yes, it's set. It wouldn't execute by double clicking in file manager otherwise.

MattZ40
Posts: 10
Joined: Tue Nov 20, 2018 5:10 pm

Re: Bash: No such file or directory

Tue Nov 20, 2018 9:27 pm

DirkS wrote:
Tue Nov 20, 2018 7:29 pm
MattZ40 wrote:
Tue Nov 20, 2018 5:57 pm
If I try to execute it in a terminal by typing "/frame/startframe.sh" I get "bash: /frame/startframe.sh: No such file or directory"
If I cd to the /frame directory and type "frame.sh" I get "frame.sh: command not found"
If I add sudo before the commands above, both return "command not found"
From the code in the scripts I would say your script is not in directory /frame, but in /home/pi/frame

So to run it you need to use either of the following commands

Code: Select all

/home/pi/frame/startframe.sh
~/frame/startframe.sh
You are correct, thank you! Although it's still a bit baffling. If I enter /home/pi/frame/startframe.sh it runs, so I should be able to put it in a script to run on boot.

The baffling part is that when I open a terminal I should be in the /home/pi directory. Doing an ls confirms this, I see the frame directory. However entering "/frame/startframe.sh" returns the "no such file or directory" error. If I switch to the frame directory, entering "startframe.sh" also returns the same error, even though I can see the file with an ls. Although if I enter "./startframe.sh" it runs. This must be something new with raspbian as I don't recall ever having to use ./ before.
Previously this was running on I think a 2012 version of noobs, Debian and laptop guts before that. It's an electronic pic frame that hangs on the wall and I don't mess with it if I can help it. I made it over 15 years ago from instructions in a Popular Mechanics magazine, back before you could buy an electronic pic frame.

DirkS
Posts: 9897
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Bash: No such file or directory

Tue Nov 20, 2018 10:00 pm

MattZ40 wrote:
Tue Nov 20, 2018 9:27 pm
The baffling part is that when I open a terminal I should be in the /home/pi directory. Doing an ls confirms this, I see the frame directory. However entering "/frame/startframe.sh" returns the "no such file or directory" error. If I switch to the frame directory, entering "startframe.sh" also returns the same error, even though I can see the file with an ls. Although if I enter "./startframe.sh" it runs. This must be something new with raspbian as I don't recall ever having to use ./ before.
There 'is' nothing with Raspbian. It's essentially the same as in any other Linux distro

I suggest you read up on the Linux filesystem, absolute/relative paths and how and where Linux/bash looks for programs.

User avatar
scruss
Posts: 2418
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Bash: No such file or directory

Wed Nov 21, 2018 3:13 am

MattZ40 wrote:
Tue Nov 20, 2018 9:27 pm
… However entering "/frame/startframe.sh" returns the "no such file or directory" error.
Of course - it's not in <root>/frame, but off your home directory. Missing out the ~ makes a big difference.

Using ~ and shortened paths may do weird stuff in cron or startup scripts.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

Roken
Posts: 291
Joined: Sun Dec 31, 2017 4:35 pm
Location: UK

Re: Bash: No such file or directory

Wed Nov 21, 2018 11:08 am

if you cd into /frame and type

Code: Select all

./startframe.sh
Does it work?
Headless PI. OMG, someone cut it's head off. Oh, hang on. it didn't have one to start with.

MattZ40
Posts: 10
Joined: Tue Nov 20, 2018 5:10 pm

Re: Bash: No such file or directory

Wed Nov 21, 2018 9:00 pm

Roken wrote:
Wed Nov 21, 2018 11:08 am
if you cd into /frame and type

Code: Select all

./startframe.sh
Does it work?
Yes I does, and the is script running on boot. I'll take the advice offered above and read up on absolute and relative paths. As I mentioned this thing has been hanging on the wall a long time, since I switched out the via epia-m system board that died with an RPi so I get pretty rusty. It's the only linux related thing I've attempted.
Thank you all for your advice and suggestions

Return to “Troubleshooting”