Rahul's Blog

Bash Scripting Cheatsheet

July 21, 2020

Shell is common Linux, Unix

Bash is a CLI tool to run the scripts. The shell script communicate with the kernel which in turn kernel tells the hardware what to do

To create a script file

gedit first.sh

Commands

#!/bin/bash #to the tell the path of bash

# hash is used for comments

echo "Hello World!" # prints stuff on the screen

Run the script

chmod +x first.sh # +x makes the file executable

or

chmod 755 first.sh # 755 is the octal here which is used to manage permissions

To show which command is giving which output

#!/bin/bash/ -x
echo $PATH # to know the path(run this in the root directory)

Use \ to make the long commands readable

npm install chrome inkspace vlc sublime mediaplayer \
soundrecorder vscode 

Points to remember

  • BASH is very well documented, don’t hesitate to search the web
  • Always use absolute paths in a script. Eg: /home/Documents/logo.png
  • Write detailed comments
  • ~ in terminal refers to home directory

Written by Rahul Jain         
I write code like I make sandwich