2

I'm trying to get a simple script "test1.sh" to work on my pi, but keep getting

-bash: test1: command not found

the script is literally:

#!/bin/bash

echo "Hello World!"

and called test1.sh, located in the /home/scripts directory.

I can navigate to it in terminal, but it will not run.

Iv'e set the permissions to 755 on the script and the "scripts" directory

I'm trying to run from the user pi.

any ideas what i'm doing wrong?

  • What do you get when you run /bin/bash /home/scripts/test1.sh? – Craig Feb 24 '14 at 18:40
4

You do call your script with a path in front, like /home/scripts/test1.sh or ./test1.sh, do you? What does ls -la /home/scripts/test1.sh say?

  • OR the script has to be in an environment path. Like /usr/src I think? – Piotr Kula Feb 24 '14 at 17:56
  • That might be a good idea: Add $HOME/scripts to $PATH – Wolf Feb 24 '14 at 18:01
  • ls -la /home/scripts/test1.sh says: -rwxr-xr-x 1 root root 34 Feb 24 17:27 /home/scripts/test1.sh – reggie Feb 24 '14 at 18:04
  • Why is the file owned by root? Have you tried chown pi:pi /home/scripts/test1.sh and then calling it again? – Wolf Feb 24 '14 at 18:05
  • i did "pi:pi /home/scripts/test1.sh" and tried to run it again, and yes i run it using "/home/scripts/test1.sh", but still same error. i don't understand "$HOME/scripts to $PATH". Do i have to add this to my script? – reggie Feb 24 '14 at 18:10
3

this link helped

I was editing in windows, using notepad++ and then using winscp to move it over to the PI. I needed to save it in notepad as a unix file - oops!

  • That is really wierd. I use Notepad++ and Filezilla SFTP to transfer scritps over the whole time. I do a chmod +x and use ./filename.sh and its fine. Possibly you are using another encoding (another language on your computer?) Make sure its UTF8 like most English PC's hsould default to. – Piotr Kula Feb 24 '14 at 21:32
  • An editor you can use on the Pi, in terminal or SSH, is nano - easy to use, and can have syntax highlighting enabled - see here. – Wilf Feb 25 '14 at 13:19

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.