'How do I make this file.sh executable via double click?
First off I'm using Mac.
Next, I need to execute this "file.sh" we will call it. Everytime I need to execute it I have to open Terminal and type:
cd /Users/Jacob/Documents/folderWithFileInIt
bash file.sh
This is okay, but I feel like it would be a lot quicker if I make the file execute on double click, don't you think?
So my question is, how do I make this file executable via double click?
My ideas were either:
a) type something like chmod into terminal and change permissions?
b) make a file, put code I wrote above in it ^ and then make that file executable?
c) make an automation somehow to do this?
Which way is best, or is there an even better way? Also please explain as much as you can, I'm new to Terminal. Thanks.
Solution 1:[1]
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.
Solution 2:[2]
You can just tell Finder to open the .sh file in Terminal:
- Select the file
- Get Info (cmd-i) on it
- In the "Open with" section, choose "Other…" in the popup menu
- Choose Terminal as the application
This will have the exact same effect as renaming it to .command except… you don't have to rename it :)
Solution 3:[3]
- Launch Terminal
- Type -> nano fileName
- Paste Batch file content and save it
- Type -> chmod +x fileName
- It will create exe file now you can double click and 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
Solution 4:[4]
you can change the file executable by using chmod like this
chmod 755 file.sh
and use this command for execute
./file.sh
Solution 5:[5]
nano ~/FILENAME
Write your bash script and exit nano with Ctrl + x and hit y
Make file an executable
chmod 700 ~/FILENAME
Bingo, the file turns an executable, double click to launch
Works without .sh extension or shebang (#!) prefix.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Markus Amalthea Magnuson |
| Solution 3 | Manish |
| Solution 4 | Night Coder |
| Solution 5 | AamirR |
