Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command not found error message when running script

Tags:

shell

unix

I'm learning how to make shell scripts in UNIX, but I keep coming across this stupid error. Let's say I make a script like this:

#!/bin/sh
echo HELLO

I save the file as test, and make the command executable by me with chmod 700 test. I save the file in my home directory, and (attempt) to run the file like so:

./test

Only for UNIX to reply back:

./test: Command not found.

What is going on? When I type out ls -l, there is an asterisk next to the file name. That wasn't there before I used the chmod command. Can anyone tell me what I'm doing wrong?

like image 339
Waffles Avatar asked Oct 05 '10 19:10

Waffles


2 Answers

Make it executable:

chmod +x ./test

and make sure you save your file in Unix file format. And: check if your partition is executable (mount).

like image 191
ivy Avatar answered Oct 13 '22 18:10

ivy


I had the same problem where I copied the file from Windows to Linux and tried to execute it. I did all suggestions above but nothing helped until I did a dos2unix on the file and that fixed it. It may not be the case for you, but just putting it out there

like image 44
Dula Avatar answered Oct 13 '22 18:10

Dula