#!/bin/bash # this is shibang use this so if your shell is not default for bin bash this will still make it run
echo hello world # this is used to print something on the screen Flags: -e —> is used to interpret blackslash escape for example \n for a new line will work if echo has an -e flag e.g echo -e “here \n a new line “ OR echo -e “the value for \$a is: $a”
cat file.txt # this will display the contant of the file, it can also be used to write to a file OR create a file and write to it e.g —> <cat >> file.txt> to append to a file and <cat > file.txt> to overwrite a file , it will take your input and then to finish press ctrl + d
: ‘ this is used for multiple line comments ‘
any_value this is also used for multiple line comments any_value
$variable
# To call a variable use dollar sign $ for example a=10 echo $a
Note : if you call a variable using ${var1}
method then this method is usefull for modifying the variable , So in other words you can use this way to modify and call a variable for Example: echo “${name:0:3}”
will output the value of name but from index 0 to index 3 OR for Example echo ${MESSAGE/learning/Reading} this will replace learning with reading in the valuea=10
# to assign a variable Note that you cannot use space when signing a variable for example a = 10 this will not work and will generate an error$(command)
is used in Bash scripting to capture the output of a command and store it in a variable. for example a=$(ls)
, the ls command lists the files and directories in the current directory, and its output is captured and stored in the variable a. so echo $a
will list everything that was stored in the directory when the variable was signedread name
# ( Read is used to take input from the user ). this will take the input and make a variable named name for example hello from terminal
read -p "Enter your name: " name
# this is a command to take an input . <read> is used for taking input <-p> is used to display the message before taking input and <name> is then signing a value to the taken input$name
this will print the value of name that is hello in the terminal # if you have used read without arguments then use echo $replytr
command