Bash Shell Scripting

 What is my shell type?

abhilash@DESKTOP-J286E82:~$ echo $0

-bash

first script:-

abhilash@DESKTOP-J286E82:~/myscripts$ cat 01_basic.sh

#!/bin/bash

echo "hey buddy!"

Run script:-

./script.sh

control + c:- to terminate

control + z:- to stop


make sure the script should be having the execute permissions


abhilash@DESKTOP-J286E82:~/myscripts$ chmod 764 01_basic.sh

abhilash@DESKTOP-J286E82:~/myscripts$ ls -lart

total 0

-rwxrw-r-- 1 abhilash abhilash  33 Oct 15 19:56 01_basic.sh

drwxr-x--- 1 abhilash abhilash 512 Oct 15 19:56 ..

drwxr-xr-x 1 abhilash abhilash 512 Oct 15 19:56 .

abhilash@DESKTOP-J286E82:~/myscripts$ ./01_basic.sh

hey buddy!


in this above way owner of script should be given a permission for execution i.e. it should be a executable script and read write as well.

the second way is use bash i.e. bash script name

comments:-

abhilash@DESKTOP-J286E82:~/myscripts$ cat 02_basic.sh

echo "cheking comments"

#this is single line comment

abhilash@DESKTOP-J286E82:~/myscripts$bash 02_basic.sh

cheking comments


multi line comments:-

abhilash@DESKTOP-J286E82:~/myscripts$ cat 02_basic.sh

echo "cheking comments"

#this is single line comment

<<this

it is a multi

line comment

this

abhilash@DESKTOP-J286E82:~/myscripts$ bash 02_basic.sh

cheking comments

#!/bin/bash when used in scripts is used to instruct the operating system to use bash as a command interpreter.

what are the variables:-

$ sign is used to know that is variable

#!/bin/bash

#script t show how to use the variables

a=10

name=prashant

age=28


echo "my variable name is $name"

abhilash@DESKTOP-J286E82:~/myscripts$ bash 03_vardemo.sh
my variable name is prashant

taking input from the user in linux :- need to used read

arithemetic operations:-

Comments

Popular posts from this blog

50 Linux Commands You Should Know