1

A beginner unix shell user question:

When I call a sh file in terminal: Why do I need to prefix it with self folder and slash: ./ ?

What are the alternatives?

Biasu
  • 439
  • 10
  • 19

2 Answers2

2

That tells the shell that you want to run a program that exists in your current directory. If that directory already exists in PATH - check with :

echo ${PATH}

then you don't need to use it and you can drop the ./ part.

Your script also needs to have the x bit set with chmod and the first line must tell the shell what new shell to spawn, see -

What is the preferred Bash shebang?

Simon Denvir
  • 116
  • 4
1

There's a very good description of the difference between running sh script.sh and just ./script.sh here.

Hopefully it helps.

ruaanvds
  • 110
  • 5