forked from logicopslab/BashScripting
-
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
logicopslab
committed
Dec 15, 2021
1 parent
d99c5b8
commit 1f5f66b
Showing
10 changed files
with
225 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,20 @@ | ||
#!/bin/bash | ||
|
||
a=10 | ||
b=20 | ||
|
||
add=$((a + b)) | ||
echo Addition of a and b are $add | ||
|
||
sub=$((a - b)) | ||
echo Subtraction of a and b are $sub | ||
|
||
mul=$((a * b)) | ||
echo Multiplication of a and b are $mul | ||
|
||
div=$((a / b)) | ||
echo division of a and b are $div | ||
|
||
mod=$((a % b)) | ||
echo Modulus of a and b are $mod | ||
|
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,46 @@ | ||
#!/bin/bash | ||
|
||
a=10 | ||
b=20 | ||
|
||
if(( $a==$b )) | ||
then | ||
echo a is equal to b. | ||
else | ||
echo a is not equal to b. | ||
fi | ||
|
||
if(( $a!=$b )) | ||
then | ||
echo a is not equal to b. | ||
else | ||
echo a is equal to b. | ||
fi | ||
|
||
if(( $a<$b )) | ||
then | ||
echo a is less than b. | ||
else | ||
echo a is not less than b. | ||
fi | ||
|
||
if(( $a<=$b )) | ||
then | ||
echo a is less than or equal to b. | ||
else | ||
echo a is not less than or equal to b. | ||
fi | ||
|
||
if(( $a>$b )) | ||
then | ||
echo a is greater than b. | ||
else | ||
echo a is not greater than b. | ||
fi | ||
|
||
if(( $a>=$b )) | ||
then | ||
echo a is greater than or equal to b. | ||
else | ||
echo a is not greater than or equal to b. | ||
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,25 @@ | ||
#!/bin/bash | ||
|
||
a=true | ||
b=false | ||
|
||
if [[ "$a" == "true" && "$b" == "false" ]]; | ||
then | ||
echo Both conditions are true. | ||
else | ||
echo Both conditions are not true. | ||
fi | ||
|
||
if [[ "$a" == "true" || "$b" == "false" ]]; | ||
then | ||
echo At least one of them is true. | ||
else | ||
echo None of them is true. | ||
fi | ||
|
||
if [[ ! "$a" == "true" ]]; | ||
then | ||
echo "a" was initially false. | ||
else | ||
echo "a" was initially true. | ||
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,25 @@ | ||
#!/bin/bash | ||
|
||
a=7 | ||
b=4 | ||
|
||
b_AND=$(( a&b )) | ||
echo Bitwise AND of a and b is $b_AND | ||
|
||
b_OR=$(( a|b )) | ||
echo Bitwise OR of a and b is $b_OR | ||
|
||
b_XOR=$(( a^b )) | ||
echo Bitwise XOR of a and b is $b_XOR | ||
|
||
b_Complement=$(( ~a )) | ||
echo Bitwise Compliment/NOT of a is $b_Complement | ||
# n -> -(n+1) | ||
|
||
l_shift=$(( a<<2 )) | ||
echo Left Shift of a is $l_shift | ||
# 00000111 << 00001110 << 00011100 | ||
|
||
r_shift=$(( b>>2 )) | ||
echo Right Shift of b is $r_shift | ||
# 00000100 >> 00000010 >> 00000001 |
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,38 @@ | ||
#!/bin/bash | ||
|
||
FileName="04.Bitwise.sh" | ||
|
||
if [ -e $FileName ] | ||
then | ||
echo Yes! The file exists | ||
else | ||
echo No! The file doesn"'"t exist | ||
fi | ||
|
||
if [ -s $FileName ] | ||
then | ||
echo File is not empty. | ||
else | ||
echo File is empty. | ||
fi | ||
|
||
if [ -r $FileName ] | ||
then | ||
echo File has read access. | ||
else | ||
echo File does not has read access. | ||
fi | ||
|
||
if [ -w $FileName ] | ||
then | ||
echo The file has write access. | ||
else | ||
echo The file does not has write access. | ||
fi | ||
|
||
if [ -x $FileName ] | ||
then | ||
echo The file has execute access. | ||
else | ||
echo The file doesn"'"t has execute access. | ||
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,20 @@ | ||
#!/bin/bash | ||
|
||
#Initializing two variables | ||
|
||
a=20 | ||
b=40 | ||
|
||
# Equal or Not check | ||
|
||
if [ $a == $b ] | ||
then | ||
echo "a is equal to b" | ||
fi | ||
|
||
# Not equal check | ||
|
||
if [ $a != $b ] | ||
then | ||
echo "a is not equal to b" | ||
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 | ||
|
||
# Initializing a and b as variables | ||
|
||
a=20 | ||
b=20 | ||
|
||
if [ $a == $b ] | ||
then | ||
echo "a is equal to b" | ||
else | ||
echo "a is not equal to b" | ||
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,9 @@ | ||
number=4 | ||
|
||
if [ $number -eq 1 ]; then | ||
echo value of number is 1 | ||
elif [ $number -eq 2 ]; then | ||
echo value of number is 2 | ||
else | ||
echo Invalid value | ||
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 | ||
|
||
total=10 | ||
|
||
if [ $total -eq 1000 ] | ||
then | ||
echo "total is equal to 1000" | ||
elif [ $total -lt 1000 ] | ||
then | ||
echo "Total is less than 1000" | ||
else | ||
echo "Total is greater than 1000" | ||
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 | ||
|
||
DOGS="husky" | ||
|
||
#Pass the variable in string | ||
|
||
case "$DOGS" in | ||
#case 1 | ||
"indie") echo "Found in moderate temperature places" ;; | ||
|
||
#case 2 | ||
"scoobydoo") echo "Found only in cartoons" ;; | ||
|
||
#case 3 | ||
"husky") echo "Found in very cold places" ;; | ||
esac |