-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 796be2c
Showing
48 changed files
with
566 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
|
||
function welcomeNote { | ||
|
||
echo "......................." | ||
echo "Welcome" | ||
echo "......................." | ||
} | ||
|
||
|
||
Welcome(){ | ||
echo "......................." | ||
echo "Welcome" | ||
echo "......................." | ||
|
||
} | ||
|
||
#to Call our function | ||
|
||
welcomeNote | ||
welcomeNote | ||
welcomeNote | ||
Welcome | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
function welcomenote { | ||
echo "......................." | ||
echo "Welcome $1" | ||
echo "Age is $2" | ||
echo "......................." | ||
} | ||
|
||
welcomenote ratu 20 | ||
welcomenote pradhul 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
set -x | ||
#to access the arguments | ||
|
||
echo "First argument is $1" | ||
echo "Second argument is $2" | ||
|
||
echo "All the arguments are - $@" | ||
echo "Number of arguments are - $#" | ||
|
||
|
||
#For loop to access the values from arguments | ||
for filename in $@ | ||
do | ||
echo "Copying file - $filename" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
# to create a user, provide username and description | ||
|
||
echo "Creating user...." | ||
echo "Username is $1" | ||
|
||
shift | ||
echo "Description is $@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
#example fo break in a lopp | ||
#we just need to confirm if a given no. if present or not | ||
|
||
no=6 | ||
|
||
for i in 1 2 3 4 5 6 7 8 9 | ||
do | ||
#break the loop if no. found | ||
if [[ $no -eq $i ]] | ||
then | ||
echo "$no is found!!!" | ||
break | ||
fi | ||
echo "Number is $i" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
#example of using continue in a loop | ||
# Suppose we only need to print odd no. | ||
|
||
for i in 1 2 3 4 5 6 7 8 9 10 | ||
do | ||
let r=$i%2 | ||
if [[ $r -eq 0 ]] | ||
then | ||
continue | ||
fi | ||
echo "odd no. is $i" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
read -p "Which site you want to check? " site | ||
|
||
ping -c 1 $site &> /dev/null | ||
#sleep 5s | ||
|
||
if [[ $? -eq 0 ]] | ||
then | ||
echo "Successfuly connected to $site." | ||
else | ||
echo "Unable to connect with $site." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
FILEPATH="/home/ratu/Desktop/programs/bash/practice/ratu.test" | ||
|
||
|
||
if [[ -f $FILEPATH ]] | ||
then | ||
echo "File exist" | ||
else | ||
echo "Creating file now..." | ||
touch $FILEPATH | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
|
||
#generating a random number between 1 to 6 | ||
|
||
no=$(( $RANDOM % 6 + 1 )) | ||
echo "Random Number is $no." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
# Checking if the user is root or not | ||
|
||
if [[ $UID -eq 0 ]] | ||
then | ||
echo "User is root" | ||
else | ||
echo "User is not root" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
ping -c 1 www.google.com > redirect.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
echo "Name of this script is ${0}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
# Example of logging | ||
|
||
logger " This is a log from ${0}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
#when set -e is there then the script is stopped when a command fails | ||
set -e | ||
|
||
pwd | ||
date | ||
cd /root | ||
hostname | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
echo "HEY buddy!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
echo "checking comments" | ||
|
||
#this is a single line comment | ||
|
||
<<comment | ||
this | ||
is a multiline | ||
COMMENT | ||
comment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
|
||
a=10 | ||
name="ratu" | ||
age=18 | ||
|
||
echo "My name is $name and age is $age" | ||
|
||
name="paul" | ||
|
||
echo "my name is $(hostname)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
readonly variable="svce" | ||
|
||
echo $variable | ||
|
||
|
||
#read only variable cannot be initiated with a new value | ||
variable="rec" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
myarray=( 1 20 30.5 Hello "HEY buddy!" ) | ||
|
||
|
||
echo"all the values in array are ${myarray[*]}" | ||
echo "${myarray[2]}" | ||
|
||
#how to fin no. of avlues in an array | ||
|
||
echo "NO.of values, length of an array is ${#myarray[*]}" | ||
|
||
echo "values form index 2-3 ${myarray[*]:2:2}" | ||
|
||
|
||
#updating our array withh new values | ||
myarray+=( new apple 30 ) | ||
|
||
echo "values of new array are ${myarray[*]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
#how to store the key value pairs | ||
#declaring a array | ||
declare -A myarray | ||
|
||
myarray=( [name]=ratu [age]=18 [city]=chennai ) | ||
|
||
echo "Name is ${myarray[name]}" | ||
|
||
echo "Age is ${myarray[age]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
myvar="Hey buddy, how are you?" | ||
|
||
myvarlength=${#myvar} | ||
echo "Length of the myvar is $myvarlength" | ||
|
||
echo "Upper case is ---${myvar^^}" | ||
echo "Lower case is ---${myvar,,}" | ||
|
||
#To replace a string here replace 1st term by 2nd one | ||
newvar=${myvar/buddy/ratu} | ||
echo "NEW VAR is ---${newvar}" | ||
|
||
#To slice a string :1st number is starting point :2nd number is the count of words to slice | ||
|
||
echo "After slice ${myvar:4:5}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
|
||
read -p "What is your name?" name | ||
|
||
echo "Your name is $name" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
#Maths Calculation | ||
x=10 | ||
y=2 | ||
|
||
|
||
#won't work | ||
mul=$x*$y | ||
echo "The multiplied value is :$mul" | ||
|
||
|
||
#should use let command to work | ||
|
||
let mul=$x*$y | ||
echo "the multiplied value is :$mul" | ||
|
||
let sum=$x+$y | ||
echo "the sum is $sum" | ||
|
||
#There is another version where we can also use double brackets to get the action of let command | ||
|
||
echo "subtraction is $(($x-$y))" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
read -p "Enter your marks: " marks | ||
|
||
if [[ $marks -gt 40 ]] | ||
then | ||
echo "Your are PASS." | ||
else | ||
echo "You are FAIL!!" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
|
||
read -p "Enter your marks: " marks | ||
|
||
if [[ $marks -ge 80 ]] | ||
then | ||
echo "1st Division." | ||
elif [[ $marks -ge 60 ]] | ||
then | ||
echo "2nd Division" | ||
elif [[ $marks -ge 40 ]] | ||
then | ||
echo "3rd Division" | ||
else | ||
echo "You are FAIL!!" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
echo "Provide an option" | ||
echo "a for Print date" | ||
echo "b for list of scripts" | ||
echo "c to check the current location" | ||
|
||
read choice | ||
|
||
case $choice in | ||
a)date;; | ||
b)ls;; | ||
c)pwd;; | ||
*)echo "Kindly provide a valid input." | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
#AND OPERATOR | ||
|
||
read -p "What is your age?" age | ||
read -p "Your country: " country | ||
|
||
if [[ $age -ge 18 ]] || [[ $country == "india" ]] | ||
then | ||
echo "You can vote" | ||
else | ||
echo "You can't vote" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
#can be used instead of if-else statement | ||
#cond1 & if statement || else statement | ||
|
||
age=18 | ||
|
||
[[ $age -ge 18 ]] && echo "Adult" || echo "minor" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
for i in 1 2 3 4 5 6 7 8 9 10 | ||
do | ||
echo "Number is $i" | ||
done | ||
|
||
#for strings | ||
for name in Rathina Devan | ||
do | ||
echo "Name is $name" | ||
done | ||
|
||
#for iterating through numbers | ||
|
||
for i in {1..5} | ||
do | ||
echo "number is $i" | ||
sleep 3s | ||
done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
#getting values from a file names.txt | ||
|
||
FILE="/home/ratu/Desktop/programs/bash/practice/names.txt" | ||
|
||
for name in $(cat $FILE) | ||
do | ||
echo "Name is $name" | ||
done |
Oops, something went wrong.