vanlooverenkoen
vanlooverenkoen

Reputation: 2301

Can't run a script

I tried to create a script in linux, on a Synology server over SSH

so I wrote a file test.sh

#!/bin/bash
echo "this is a test"

I saved the file. after that I did

chmod 755 test.sh

the I did

./test.sh

then i got this error

-ash "./test.sh" is not found

the file was created in

/root

I don't understand

Upvotes: 1

Views: 4052

Answers (2)

Jens
Jens

Reputation: 72667

This is one of the quirks with hash bang programs. If the interpreter is not found (i.e. the program interpreting the script), you don't get a completely useful error like /bin/bash: no such file, but a completely useless and misleading test.sh: not found.

If this isn't in the Unix Hater's Handbook, it should be. :-)

You can either use #!/bin/sh or #!/path/to/bash or #!/usr/bin/env bash (which searches PATH for bash).

Upvotes: 1

melpomene
melpomene

Reputation: 85767

Your shell (ash?) is trying to execute your script and is getting an ENOENT (no such file or directory) error code back. This can refer to the script itself, but in this case it refers to the interpreter named in the #! line.

That is, /bin/bash does not exist and that's why the script couldn't be started.

Workaround: Install bash or (if you don't need any bash specific features) change the first line to #!/bin/sh.

Upvotes: 3

Related Questions