Basic shell scripting tutorial for Beginners - Linux/Unix

Basic shell scripting tutorial for Beginners - Linux/Unix

In this article, we will learn basic shell scripting for beginners. It is described in very simple language.



What is BASH?

Bash is a command language interpreter. It is widely available on various operating systems and is a default command interpreter on most GNU/Linux systems. BASH stand for ‘Bourne-Again SHell’.




Basic Commands with Example:- 

#! /bin/bash

#To view of the command
echo "Hello world"
Output: 
>Hello world

#To view of System variable command

echo $PWD
echo $HOME
echo $BASH

Output:
>/c/Users/username/Desktop/RDS/Shell
/c/Users/username /bin/bash

#To view user variable command

name=ram
echo "My name is $name"
Output:
>My name is ram
name=rakesh
echo "my brother name is $name"

Output:
>my brother name is rakesh

value=100$
echo "ram value is $value"

Output:
>ram value is 100$

#To use read command to type any name/value and get output with name/value
echo "Enter name : "
read name

echo "Entered name is $name"

Output:


echo "What is your occupation : "
read work
echo "My occupation is $work"

Output:
>My occupation is work

#To use read command after enter in same line

read -p "username : " user_var
echo "username is : $user_var"
Output:
>username is rajesh

#To use read command after entering in same line and password is hidden

read -sp "password : " pass_var
echo "password is : $pass_var"

Output:
>password is 1234

read -p "what is your name: " user_var
read -sp "what is your password: " password_var
echo
echo "My name is $user_var"
echo "My password is $password_var"

Output:
>My name is rajesh
My password is 12344

#To pass argument with multiple variable name such as ./shell.sh ram nam tam

echo $0 $1 $2 $3

Run script on terminal:
>./shell ram nam tam

Output:

>./shell ram nam tam

#Please see screenshot for the basic argument which is used in bash script



args=("$@")
echo ${args[0]} ${args[1]} ${args[2]}
echo $@
echo $#


Share:

0 comments

Please leave your comments...... Thanks