Saturday, June 6, 2026

 Bash Shell

Bash is used to run commands and write scripts on Unix/Linux systems. Bash is the default shell on most Linux and macOS systems. Bash added features from other shells, such as the Korn shell (ksh) and C shell (csh),

[root@localhost ~]# echo $SHELL

/bin/bash

[root@localhost ~]# cat /etc/shells       --available shells

/bin/sh                                     --à cannot find many function, command

/bin/bash

/usr/bin/sh

/usr/bin/bash

[root@localhost ~]# echo "Hello World"                    àin terminal

Hello World

[root@localhost ~]# vi shell1.sh

[root@localhost ~]# ls -l

-rw-r--r--  1 root root      32 Jun  6 13:05 shell1.sh

[root@localhost ~]# bash shell1.sh

Hello World

[root@localhost ~]# env

 [root@localhost ~]# echo $PWD

/root

[root@localhost ~]# echo $PATH

/usr/share/Modules/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

[root@localhost ~]# echo $SHELL

/bin/bash

[root@localhost ~]# su – santosh                   -----à To switch to other user

santosh@localhost ~]$ echo $USER

santosh

env----------------------------------> env---user wise will change, only last for session only

[santosh@localhost ~]$ env                            

 [santosh@localhost ~]$ $PATH

-bash: /home/santosh/.local/bin:/home/santosh/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin: No such file or directory

[santosh@localhost ~]$ export NAME=centos                         here, NAME=variabler, centos=value

[santosh@localhost ~]$ env | grep NAME

HOSTNAME=localhost.localdomain

NAME=centos

LOGNAME=santosh

[santosh@localhost ~]$ var2=NEPAL

[santosh@localhost ~]$ env | grep NEPAL

[santosh@localhost ~]$ echo $var2

NEPAL

[santosh@localhost ~]$ exit            logout from user

logout

[root@localhost ~]# echo $NAME

           -----------Nothing will show

[root@localhost ~]# su - santosh

[santosh@localhost ~]$ echo $var2

 

[santosh@localhost ~]$ echo $NAME         ---doesn't show any things ......only for session

[santosh@localhost ~]$ export NAME=san

[santosh@localhost ~]$ echo $NAME

san

[santosh@localhost ~]$ export NAME=karma

[santosh@localhost ~]$ echo $NAME

karma

[santosh@localhost ~]$ unset NAME                             à To remove

[santosh@localhost ~]$ echo $NAME

 [santosh@localhost ~]$ vi exercise2.sh

[santosh@localhost ~]$  ./exercise2.sh

-bash: ./exercise2.sh: Permission denied

[santosh@localhost ~]$ chmod +x exercise2.sh                 -à To make executable file

[santosh@localhost ~]$  ./exercise2.sh

My Name is San

[santosh@localhost ~]$ cd /tmp/

[santosh@localhost tmp]$ ./exercise2.sh

-bash: ./exercise2.sh: No such file or directory   à file must run where is made

[santosh@localhost tmp]$ cd

[santosh@localhost ~]$ ls

Desktop    Downloads     Music     Public     Videos

Documents  exercise2.sh  Pictures  Templates

[santosh@localhost ~]$ mkdir -p .local/bin

[santosh@localhost ~]$ mv exercise2.sh .local/bin

[santosh@localhost ~]$ echo $PATH

/home/santosh/.local/bin:/home/santosh/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin

[santosh@localhost ~]$ cd /tmp/                  ---->run from anywhere, it works

[santosh@localhost tmp]$ exercise2.sh

My Name is San

[santosh@localhost tmp]$ cd /var/log
[santosh@localhost log]$ exercise2.sh
My Name is San

[santosh@localhost log]$ cd

[santosh@localhost ~]$ cat .local/bin/exercise2.sh

#!/bin/bash

NAME=San

echo "My Name is $NAME"


 

 

 

 


 

 

 

 

No comments:

Post a Comment