top of page
uni datacenter

Bash Scripting: Special Characters

  • Writer: rajababukarmakar
    rajababukarmakar
  • Jul 23, 2024
  • 2 min read

Updated: Aug 2, 2024


In this post, we will talk about special characters in bash scripts and how they can make our lives easier. There are many special characters; Special characters for making comments in between the codes, command separators (semicolon), terminators (double semicolon), dot commands, partial quoting (double quote), full quoting (single quote), arithmetic operators and more.


To start with, we will start with the example of adding comments in bash scripting.


Making comments in bash scripting

To make comments in bash scripting, we can use '#'. Any line starting with '#' (with the exception of '#!') is a comment and will not be executed while running the bash scripts.

# This is a comment in bash, and will not be executed

The comments can also be placed at the end of a command. Any expression or command after the '#' will be skipped from executing.

$ echo "Hello World!" # Comment starts here. Notice a space before '#' 
Hello World! 

Command separators (Semicolon)

Command separators as the name suggests, allow users to put more than one command per line.

$ echo "Hello World!"; echo "Hello World 2!" 
Hello World!
Hello World 2!

Partial quoting string (double quote)

Partial quoting ("string") allows users to preserve most of the special characters (from interpretation) in the string.


Full quoting string (single quote)

Full quoting ('string') allows users to preserve all the special characters in the string.


Comma operator

The comma operator links together a series of arithmetic operations, where all the items are evaluated but only the last item is returned.

$ let "t2 = ((a = 9, 15/3))"  # Set "a = 9" and "t2 = 15/3"

If you are interested in learning more about bash scripting, check out some more topics in our blog section. If you are interested in acquiring your own computing space, don't hesitate to contact Uni Datacenter at info@uni-datacenter.com or visit www.uni-datacenter.com 

bottom of page