Page 1 of 1

Bash: No such file or directory

Posted: Tue Nov 20, 2018 5:57 pm
by MattZ40
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

Re: Bash: No such file or directory

Posted: Tue Nov 20, 2018 7:22 pm
by Andyroo
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?

Re: Bash: No such file or directory

Posted: Tue Nov 20, 2018 7:29 pm
by DirkS
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

Re: Bash: No such file or directory

Posted: Tue Nov 20, 2018 9:01 pm
by MattZ40
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.

Re: Bash: No such file or directory

Posted: Tue Nov 20, 2018 9:27 pm
by MattZ40
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.

Re: Bash: No such file or directory

Posted: Tue Nov 20, 2018 10:00 pm
by DirkS
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.

Re: Bash: No such file or directory

Posted: Wed Nov 21, 2018 3:13 am
by scruss
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.

Re: Bash: No such file or directory

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

Code: Select all

./startframe.sh
Does it work?

Re: Bash: No such file or directory

Posted: Wed Nov 21, 2018 9:00 pm
by MattZ40
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