You are on page 1of 17

Shell programs

• Variable

• Variable in bash shell scripting is a memory


• location contain a number, a character, a
string
• no data types for a variable.
• variableReference=value

• Note : No space should be given before and


• after =

• Example

• num=10
echo

• Echo is a command in bash shell that writes its


• arguments to standard output.

• Syntax :

• echo [string]

• echo is commonly used in shell scripts to


• display a message or output the results of
• other commands.
How to Run Shell Scripts
• chmod +x shell-script-name
• Run our script as
• Syntax: ./your-shell-program-name
• Single Quote

• Use single quote when you want to literally


• print everything inside the single quote.

• Double Quote

• Use double quotes when you want to display


• the real meaning of special variables.
• First we create a variable

• variable=apple

• to get the value inside using double quotes

• echo "$variable“

• ...

• output: apple
• we use single quotes, the result will be
• different

• echo '$variable‘

• ... output:

• $variable
read

• read is a builtin command of the Bash shell.

• read is a bash builtin command to read input


• from user.

• read command reads only a single line from


• bash shell.

• Following is the syntax of read command

• read <variable_name>
• if conditional expression
• then
command(s)
• fi
• if conditional expression
• then
• Command
• elif conditional expression
• then
• Command
• else command
• fi
• for variable in list
• do
• command(s)
• done
• while condition
• do
• command(s)
• done
• bc command in Linux

• bc is basic calculator

• bc command is used for command line


• calculator.

• Arithmetic operations are the most basic in


• any kind of programming language.
• Unix operating system provides
• the bc command for doing arithmetic
calculations.
• $ echo "12+5" | bc

You might also like