Sometimes i see that few scripts are executed through \"sh\" command and sometimes through \"./\" command.I am not able to understand the exact difference between them.Please he
With sh , we can run a script that doesn’t have execute permission set on it, we run it as argument for sh, but ./ needs the permission as it is supposed to be an executable. In both cases, new shell will be created to run the script. See the below example:
root@ub18:~/shell# vi test1.sh
#!/bin/bash
my_var=hello
echo $my_var
#Shows the current shell processid
echo $$
root@ub18:~/shell# echo $$
1896
root@ub18:~/shell# sh test1.sh
hello
2093
root@ub18:~/shell# ./test1.sh
-su: ./test1.sh: Permission denied
root@ub18:~/shell# chmod +x ./test1.sh
root@ub18:~/shell# ./test1.sh
hello
2102
root@ub18:~/shell# ./test1.sh
hello
2103
root@ub18:~/shell# ./test1.sh
hello
2104
root@ub18:~/shell# sh test1.sh
hello
2106