What a .sh file is and why you need to run it differently
A .sh file is a script — a text file containing a list of commands that your computer can execute in order. Unlike a regular program you click to open, a .sh file needs permission to run and needs to be told to start from a terminal window (the command-line interface on your computer). Windows, Mac, and Linux all handle this slightly differently, but the basic idea is the same: you're telling your computer to read the file and follow its instructions.
You'll encounter .sh files when you download software from the internet, install development tools, or follow setup instructions for programming projects. The file itself is just text, but it contains commands that do real work — installing packages, configuring settings, or launching programs. Running it means executing those commands.
Key Takeaways
- On Mac and Linux, open Terminal, navigate to the folder containing the .sh file, and type bash filename.sh or ./filename.sh to run it.
- On Windows, you need Windows Subsystem for Linux (WSL) or a tool like Git Bash installed first, then use the same bash command.
- Before running a .sh file from the internet, open it in a text editor to read what commands it will execute, so you know what it does.
- If you get a "permission denied" error, type chmod +x filename.sh first to give the file permission to run.
- The file must be in your current folder, or you must type the full path to it, or the terminal won't find it.
Running a .sh file on Mac
On Mac, open the Terminal application. You can find it by pressing Command + Space, typing "terminal", and pressing Enter. A black window will open where you can type commands.
Navigate to the folder where your .sh file is located. If the file is on your Desktop, type cd Desktop and press Enter. If it's in your Downloads folder, type cd Downloads. The cd command means "change directory" — it moves you into that folder.
Once you're in the right folder, type bash filename.sh (replace "filename" with the actual name of your file) and press Enter. The script will run and execute all the commands inside it. You'll see output in the terminal as it works.
If you get an error saying "permission denied", the file doesn't have permission to run yet. Type chmod +x filename.sh and press Enter, then try the bash command again. The chmod command gives the file permission to be executed.
Running a .sh file on Windows
Windows doesn't natively run .sh files the way Mac and Linux do. You have two main options: use Windows Subsystem for Linux (WSL), which is built into Windows 10 and later, or install a tool like Git Bash.
If you have WSL installed: Open PowerShell or Command Prompt and navigate to the folder containing your .sh file using the cd command, just as you would on Mac. Then type bash filename.sh and press Enter. If you don't have WSL installed yet, search "Turn Windows features on or off" in your Start menu, check the box for "Windows Subsystem for Linux", and restart your computer.
If you're using Git Bash: Right-click in the folder where your .sh file is located and select "Git Bash Here". A terminal window will open in that folder. Type bash filename.sh and press Enter. Git Bash is a separate download from git-scm.com if you don't have it already.
Running a .sh file on Linux
On Linux, open your terminal application — the exact name depends on your distribution, but it's usually called "Terminal" or "Konsole". Navigate to the folder containing your .sh file using the cd command.
Type bash filename.sh or ./filename.sh and press Enter. Both commands work; the second one runs the file directly if it has execute permission. If you use the second form and get "permission denied", type chmod +x filename.sh first.
Reading a .sh file before you run it
Before running any .sh file you downloaded from the internet, open it in a text editor to see what it actually does. Right-click the file, select "Open With", and choose a text editor like Notepad (Windows), TextEdit (Mac), or gedit (Linux). You'll see the commands the script will execute.
Look for anything that seems suspicious or that you don't recognize. If the script is installing software, you should see the name of the software. If it's downloading files, you should see where they're coming from. If you don't understand what a command does, search for it online before running the script. This step takes two minutes and protects you from running malicious code.
Fixing common errors when running .sh files
Command not found: This usually means the terminal can't find your .sh file. Make sure you're in the correct folder by typing ls (Mac and Linux) or dir (Windows) to list all files in the current folder. You should see your .sh file in the list. If you're not in the right folder, use cd to navigate there.
Permission denied: The file doesn't have permission to run. Type chmod +x filename.sh and press Enter, then try running it again. This command only needs to be done once per file.
No such file or directory: Either the file doesn't exist, or you typed the filename wrong. Check the exact spelling and file extension. Filenames are case-sensitive on Mac and Linux, so Script.sh and script.sh are different files.
The script runs but nothing happens: Some .sh files run silently or create files in the background. Check your Downloads folder or Desktop to see if new files appeared. If the script was supposed to install something, open your Applications folder to see if a new program is there.
Understanding what happens when a .sh file runs
When you run a .sh file, your computer reads each line in order and executes the command on that line. Some commands take a few seconds; others take minutes. While the script is running, you'll see output in the terminal showing what's happening. This output is helpful for troubleshooting if something goes wrong.
Some scripts ask for your password during execution. This happens when the script needs to install software or change system settings that require administrator permission. Type your password when prompted — it won't show on screen as you type, but it's being entered. Press Enter when you're done.
Once the script finishes, you'll see a new command prompt (usually a dollar sign or percent sign) appear in the terminal. This means the script has completed and you can type a new command or close the terminal window.
Frequently Asked Questions
Can I run a .sh file by double-clicking it?
On Mac and Linux, double-clicking usually opens the file in a text editor instead of running it. You need to use the terminal and the bash command. On Windows, double-clicking won't work at all because Windows doesn't recognize .sh files. Always use the terminal method described above.
What's the difference between bash filename.sh and ./filename.sh?
Both run the same script, but bash filename.sh explicitly tells your computer to use the bash program to read the file. The ./filename.sh method runs the file directly if it has execute permission. The first method is safer if you're not sure about the file's permissions, so use that one if you're unsure.
Do I need to be in the same folder as the .sh file to run it?
No, but it's easier if you are. If the file is elsewhere, you can type the full path instead of just the filename — for example, bash /Users/yourname/Downloads/filename.sh on Mac or bash C:\Users\yourname\Downloads\filename.sh on Windows. Using cd to navigate to the folder first is simpler for most people.
What if the .sh file needs to download something from the internet?
The script will handle the download automatically — you don't need to do anything. Make sure you have an internet connection before running it. The download may take a few minutes depending on file size and your connection speed. The terminal will show progress as the download happens.
Can I edit a .sh file and save it with a different name?
Yes. Open the file in a text editor, make your changes, and save it with a new name — for example, filename-modified.sh. Make sure you keep the .sh extension. You'll need to give the new file execute permission with chmod +x before running it.