Skip to content

Commit 1f9229e

Browse files
committed
simplifications
1 parent 72b042c commit 1f9229e

27 files changed

+132
-169
lines changed

scripts/addition.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

3-
echo 'Enter the First Number :'
4-
read a
5-
echo 'Enter the Second Number :'
6-
read b
7-
x=$(expr "$a" + "$b")
8-
echo $a + $b = $x
3+
printf 'Enter the First Number: '
4+
read -r a
5+
printf 'Enter the Second Number: '
6+
read -r b
7+
x=$((a+b))
8+
printf '%s\n' "$a + $b = $x"

scripts/archive-and-encrypt.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#!/bin/bash
1+
#!/bin/sh
22
name=$1
33
path=$2
4-
tar -czvf $name.tar.gz $path
5-
gpg -c $name.tar.gz
6-
rm -rf $name.tar.gz
4+
tar -czvf "$name".tar.gz "$path"
5+
gpg -c "$name.tar.gz"
6+
rm -rf "$name.tar.gz"

scripts/armstrong.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
#!/bin/bash
2-
echo "Enter A Number"
3-
read n
1+
#!/bin/sh
2+
printf "Enter A Number: "
3+
read -r n
44
arm=0
55
temp=$n
66
while [ $n -ne 0 ]; do
7-
r=$(expr $n % 10)
8-
arm=$(expr $arm + $r \* $r \* $r)
9-
n=$(expr $n / 10)
7+
r=$((n % 10))
8+
arm=$((arm + r * r * r))
9+
n=$((n / 10))
1010
done
1111
echo $arm
12-
if [ $arm -eq $temp ]; then
12+
if [ $arm -eq "$temp" ]; then
1313
echo "Armstrong"
1414
else
1515
echo "Not Armstrong"

scripts/binary2decimal.sh

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
#!/bin/bash
2-
echo "Enter a number :"
3-
read Binary
4-
if [ $Binary -eq 0 ]; then
1+
#!/bin/sh
2+
printf "Enter a number: "
3+
read -r binary
4+
if [ "$binary" -eq 0 ]; then
55
echo "Enter a valid number "
66
return
77
else
8-
while [ $Binary -ne 0 ]; do
9-
Bnumber=$Binary
10-
Decimal=0
8+
while [ "$binary" -ne 0 ]; do
9+
decimal=0
1110
power=1
12-
while [ $Binary -ne 0 ]; do
13-
rem=$(expr $Binary % 10)
14-
Decimal=$((Decimal + (rem * power)))
11+
while [ "$binary" -ne 0 ]; do
12+
rem=$((binary % 10))
13+
decimal=$((decimal + (rem * power)))
1514
power=$((power * 2))
16-
Binary=$(expr $Binary / 10)
15+
binary=$((binary / 10))
1716
done
18-
echo " $Decimal"
17+
echo " $decimal"
1918
done
2019
fi

scripts/color.sh

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

3-
DARKGRAY='\033[1;30m'
4-
RED='\033[0;31m'
5-
LIGHTRED='\033[1;31m'
6-
GREEN='\033[0;32m'
7-
YELLOW='\033[1;33m'
8-
BLUE='\033[0;34m'
9-
PURPLE='\033[0;35m'
10-
LIGHTPURPLE='\033[1;35m'
11-
CYAN='\033[0;36m'
12-
WHITE='\033[1;37m'
13-
DEFAULT='\033[0m'
14-
15-
COLORS=($DARKGRAY $RED $LIGHTRED $GREEN $YELLOW $BLUE $PURPLE $LIGHTPURPLE $CYAN $WHITE )
16-
17-
for c in "${COLORS[@]}";do
18-
printf "\r $c LOVE $DEFAULT "
19-
sleep 1
20-
done
3+
for c in 90 31 91 32 33 34 35 95 36 97 ;do
4+
printf '\r \033[%sm LOVE \033[0m ' "$c"
5+
sleep 1
6+
done

scripts/convertlowercase.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/bin/bash
22

3-
echo -n "Enter File Name : "
4-
read fileName
3+
printf "Enter File Name: "
4+
read -r file
55

6-
if [ ! -f $fileName ]; then
7-
echo "Filename $fileName does not exists"
6+
if [ ! -f "$file" ]; then
7+
echo "Filename $file does not exists"
88
exit 1
99
fi
1010

11-
tr '[A-Z]' '[a-z]' <$fileName >>small.txt
11+
tr '[:upper:]' '[:lower:]' <"$file" >>small.txt

scripts/count-lines.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
#!/usr/bin/env bash
1+
#!/bin/sh
22

3-
for F in *
4-
do
5-
if [[ -f $F ]]
6-
then
7-
echo $F: $(cat $F | wc -l)
8-
fi
9-
done
3+
wc -l ./*

scripts/dec2hex.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
#!/bin/bash
2-
3-
printf "0x%x\n" $1
1+
#!/bin/sh
2+
printf "0x%x\n" "$1"

scripts/directorysize.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22

3-
echo " Enter your directory: "
4-
read x
3+
printf " Enter your directory: "
4+
read -r x
55
du -sh "$x"

scripts/division.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
2-
echo .Enter the First Number: .
2+
printf 'Enter the First Number: '
33
read a
4-
echo .Enter the Second Number: .
4+
printf "Enter the Second Number: "
55
read b
6-
echo "$a / $b = $(expr $a / $b)"
6+
echo "$a / $b = $((a / b))"

0 commit comments

Comments
 (0)