By default, *.sh
files are opened in a text editor (Xcode or TextEdit). To create a shell script that will execute in Terminal when you open it, name it with the “command” extension, e.g., file.command
. By default, these are sent to Terminal, which will execute the file as a shell script.
You will also need to ensure the file is executable, e.g.:
chmod +x file.command
Without this, Terminal will refuse to execute it.
Note that the script does not have to begin with a #!
prefix in this specific scenario, because Terminal specifically arranges to execute it with your default shell. (Of course, you can add a #!
line if you want to customize which shell is used or if you want to ensure that you can execute it from the command line while using a different shell.)
Also note that Terminal executes the shell script without changing the working directory. You’ll need to begin your script with a cd
command if you actually need it to run with a particular working directory.
Remove the extension altogether and then double-click it. Most system shell scripts are like this. As long as it has a shebang it will work.
You can just tell Finder to open the .sh
file in Terminal:
This will have the exact same effect as renaming it to .command
except… you don't have to rename it :)
File name should in under double quotes. Since i am using Mac->In my case content of batch file is
cd /Users/yourName/Documents/SeleniumServer
java -jar selenium-server-standalone-3.3.1.jar -role hub
It will work for sure
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With