DEV Community

Ranjith srt
Ranjith srt

Posted on • Edited on

shell scripting

Microsoft apps :

i Ubuntu

Enable WSL :

setting - search turn on off features - on windows subsystem for linux - restart

visual studio code - Extension - WSL

pwd
ls
touch main.sh

cat/etc/shells

chmod +x main.sh

run script :

output:

print :

variable :

variable rules :

type of variables :

commend

environment variables or system variables :

export AGE=26 -set env var
printenv - list env

read - input

operator's:

control statements:

if syntax :

if [expression] True or false
then
statement
fi

Example :

if Else syntax :

if [expression] True
then
statement 1
else Fasle
statement 2
fi

Else if :

if [ expressionl ]
then
statementl
statement2
elif [ expression2 ]
then
statement3
statement4
statements
else
statement 5
fi

Example :

/bin/bash

read -p "Enter a number:" number

if [ $number -gt 10 ];
then
echo "The number is greater than 10. "
elif [ $number -eq 10 ] ;
then
echo "The number is equal to 10. "
else
echo "The number is less than IO. "
f1

Nested if :

if[ expressionl ]
then
statementl
statement2
else
if[ expression2 ]
then
statement3
f1
f1

switch case :

loops :

For loop :

function :

f arg :

Top comments (0)