bash scripts: the basics
published 28 January 2022 ยท 2 min read
For lightweight, fun automated scripts.
Last semester at uni, I got my first taste at experiencing the beauty of bash scripts. Steep learning curve? Definitely. Foreign? Definitely. Fulfilling? Also definitely.
So, with this series of articles, I hope to introduce you to some new things and help you, my reader, gain a good basic grasp when it comes to bash scripts.
(In case you haven't noticed, this is just part 1. There's more to come!)
Setup
If you're on a Mac or a Linux-based system, no worries: bash is most likely already installed on your system.
If you are using Windows 10, try this tutorial out, and if you are on Windows 11, check this one out.
echo "hello world!"
Because it wouldn't be a tutorial without printing "hello world" onto the screen. Open your favourite code editor, create a file named hello.sh, and then write down:
#!/bin/sh
echo hello world!Save this onto your computer as hello.sh.
To run this script, just type sh hello.sh onto your terminal window. You should see
hello world!printed onto your screen!
essential commands
There are a couple of commands you should know in order to become productive with bash:
cd: change directory. For example, if your current directory is ~/Documents, and you typecd loona, you will be taken to ~/Documents/loona.mkdir: make directories. For example, if your current directory is ~/Desktop and you typemkdir loona aespa, then in your Desktop folder you will see folders named loona and aespa.ls: list everything in the directory.rmdir: remove a directory.rm: remove a file.mv: move (also used to rename files).cp: copypwd: stands forprint working directory
essential names
..: the parent directory.: the current directory-: the previous directory~: home directory/: root directory
Those are just some of the most common things you need to know to get started with bash. Stay tuned for part 2!