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"
[santosh@localhost ~]$ mkdir $HOME/.local/bin here, $HOME=variable or use [santosh@localhost ~]$ mkdir -p ~/.local/bin where, ~/ any user home directory
mkdir: cannot create directory ‘/home/santosh/.local/bin’: File exists
[santosh@localhost ~]$ mkdir -p $HOME/.local/bin
[santosh@localhost ~]$ echo $HOME
/home/santosh
[santosh@localhost ~]$ vi exercise2.sh
[santosh@localhost ~]$ chmod +x exercise2.sh
[santosh@localhost ~]$ ./exercise2.sh
Hello testing
[santosh@localhost ~]$ cd /tmp/
[santosh@localhost tmp]$ ls
[santosh@localhost tmp]$ ./exercise2.sh
-bash: ./exercise2.sh: No such file or directory
[santosh@localhost tmp]$ $HOME/exercise2.sh à To execute, give full path
Hello testing
OR,
[santosh@localhost tmp]$ cd
[santosh@localhost ~]$ mkdir bin
[santosh@localhost ~]$ mv exercise2.sh /bin/
mv: cannot move 'exercise2.sh' to '/bin/exercise2.sh': Permission denied
[santosh@localhost ~]$ sudo mv exercise2.sh /bin/
[sudo] password for santosh:
[santosh@localhost ~]$ cd /bin/
[santosh@localhost bin]$ ls
[santosh@localhost bin]$ cd /tmp/
[santosh@localhost tmp]$ exercise2.sh
My Name is San here output is My Name is San not Hello tesing because of precedienty of ./local/bin
[santosh@localhost tmp]$ cat ~/.local/bin/exercise2.sh
#!/bin/bash
NAME=San
echo "My Name is $NAME"
[santosh@localhost tmp]$ cat ~/bin/exericise2.sh
cat: /home/santosh/bin/exericise2.sh: No such file or directory
[santosh@localhost tmp]$ echo $PATH
/home/santosh/.local/bin:/home/santosh/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin --Ã shows on my name is because of precedencity /.local/bin
[santosh@localhost tmp]$ cd /bin/
[santosh@localhost bin]$ mv exercise2.sh exercise3.sh
mv: cannot move 'exercise2.sh' to 'exercise3.sh': Permission denied
[santosh@localhost bin]$ sudo mv exercise2.sh exercise3.sh
[sudo] password for santosh:
[santosh@localhost bin]$ cd /tmp/
[santosh@localhost tmp]$ ls
[santosh@localhost tmp]$ exercise3.sh
Hello testing
[root@localhost ~]# cd /bin
[root@localhost bin]# ls
[root@localhost bin]# vim exercise4.sh
root@localhost bin]# chmod +x exercise4.sh
[root@localhost bin]# vim exercise4.sh
[root@localhost bin]# exercise4.sh
value1 my first variable
Enter your name
san
Your name is san
:Testing