If you can type and you have mild control issues with your computer then shell scripting is the tiny addiction that becomes very useful. This guide walks through creating a runnable script in Ubuntu using the terminal and a minimum of ceremony, with honest explanations and a few jokes at your future self.
Create a new text file with your editor of choice. Yes nano is fine, yes vim is a flex, and yes you can use touch if you prefer pretending the file made itself.
nano hello.sh
# or
touch hello.sh && nano hello.sh
Put a shebang at the top so the kernel knows which interpreter to call. A portable and common choice is this line.
#!/usr/bin/env bash
echo "Hello world"
The shebang tells Linux to run the rest of the file with bash. If you skip it the file is still text and you can run it by invoking an interpreter explicitly, but including the shebang makes your script behave like a tiny program.
Files need the execute bit set before the kernel will let you run them directly. This is not witchcraft, it is file permissions.
chmod +x hello.sh
That grants execute permission for the file owner. You can confirm with ls -l to see the x flag in the mode string. If you need other users to run it adjust permissions or install it into a shared directory.
Run it from the current directory like this.
./hello.sh
Or call an interpreter explicitly which ignores the file executable bit.
bash hello.sh
If you put the script in a directory that is in your PATH then you can run it by name from anywhere. Common choices are ~/bin or /usr/local/bin depending on whether you want a single user or system wide tool.
There you go. You turned a plain text file into a small automation that saves keystrokes and gives you a tiny sense of mastery over Ubuntu, bash, and the terminal. Be kind to your scripts and they will be kinder to your future self.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.