How to Run a Bash Script File in Command Line Using Terminal?
Updated: August 8th, 2022, 09:56:04 IST
Published:
August 8th, 2022
Shell is a command-line interpreter that allows users to communicate with the operating system. It is in charge of receiving user input and showing the results. Why not automate the execution of the same set of instructions at the command line?
Running a Bash Script File using Command line terminal:
A good script always contains comments that make it readable.
To launch any project or website, I found myself entering the same things again and over. Here's how I wrapped it up in a script to save me keystrokes at the command line.
1) Make a new text file with the extension.sh.
For my website, I made a new file named deploy.sh
2) Add #!/bin/bash at the end.
This is required for the "make it executable" step.
3) Insert lines that you would ordinarily write at the command line.
Here's the complete contents of the file I use to distribute general updates to as an example.
deploy.sh
#!/bin/bash
git add .
git commit -m "Updates"
git push
4) Type chmod u+x YourScriptFileName at the command prompt. To make mine executable, I used chmod u+x deploy.sh
5) Use it whenever you want!
Now, everytime I make updates to my website, I simply run ./deploy.sh and everything is fine. Done.