简体   繁体   中英

shell terminal: sh file prefix ./

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?

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?

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

Hopefully it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM