Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 01927f7

Browse files
authored
Merge pull request ruanyf#30 from 6gk/master
simplifications
2 parents 72b042c + 6e837f9 commit 01927f7

29 files changed

+142
-181
lines changed

scripts/addition.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
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+
echo -n 'Enter the First Number: '
4+
read -r a
5+
echo -n 'Enter the Second Number: '
6+
read -r b
7+
echo "$a + $b = $((a+b))"

scripts/affect.sh

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

33
arr=('-' '\' '|' '/')
44
while true; do
55
for c in "${arr[@]}"; do
6-
printf "\r %c " $c
6+
echo -en "\r $c "
77
sleep .5
88
done
99
done

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+
#!/usr/bin/env bash
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: 8 additions & 8 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+
#!/usr/bin/env bash
2+
echo -n "Enter A Number: "
3+
read -r n
44
arm=0
55
temp=$n
6-
while [ $n -ne 0 ]; do
7-
r=$(expr $n % 10)
8-
arm=$(expr $arm + $r \* $r \* $r)
9-
n=$(expr $n / 10)
6+
while [ "$n" -ne 0 ]; do
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+
#!/usr/bin/env bash
2+
echo -n "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+
#!/usr/bin/env bash
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+
echo -en "\r \e[${c}m LOVE \e[0m "
5+
sleep 1
6+
done

scripts/convertlowercase.sh

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

3-
echo -n "Enter File Name : "
4-
read fileName
3+
echo -n "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: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
#!/usr/bin/env bash
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+
#!/usr/bin/env bash
2+
printf "0x%x\n" "$1"

scripts/decimal2binary.sh

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

33
for ((i = 32; i >= 0; i--)); do
4-
r=$((2 ** $i))
4+
r=$((2 ** i))
55
Probablity+=($r)
66
done
77

@@ -11,7 +11,7 @@ done
1111
}
1212

1313
echo -en "Decimal\t\tBinary\n"
14-
for input_int in $@; do
14+
for input_int; do
1515
s=0
1616
test ${#input_int} -gt 11 && {
1717
echo "Support Upto 10 Digit number :: skiping \"$input_int\""
@@ -22,12 +22,12 @@ for input_int in $@; do
2222

2323
for n in ${Probablity[@]}; do
2424

25-
if [[ $input_int -lt ${n} ]]; then
25+
if [[ $input_int -lt $n ]]; then
2626
[[ $s == 1 ]] && printf "%d" 0
2727
else
28-
printf "%d" 1
28+
echo -n 1
2929
s=1
30-
input_int=$(($input_int - ${n}))
30+
input_int=$((input_int - n))
3131
fi
3232
done
3333
echo -e

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+
echo -n "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+
echo -n 'Enter the First Number: '
33
read a
4-
echo .Enter the Second Number: .
4+
echo -n "Enter the Second Number: "
55
read b
6-
echo "$a / $b = $(expr $a / $b)"
6+
echo "$a / $b = $((a / b))"

scripts/encrypt.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
echo "Welcome, I am ready to encrypt a file/folder for you"
44
echo "currently I have a limitation, Place me to the same folder, where a file to be encrypted is present"
55
echo "Enter the Exact File Name with extension"
6-
read file
6+
read -r file
77
# decryption command
88
# gpg -d filename.gpg > filename
9-
gpg -c $file
9+
gpg -c "$file"
1010
echo "I have encrypted the file sucessfully..."
1111
echo "Now I will be removing the original file"
12-
rm -rf $file
12+
rm -rf "$file"

scripts/evenodd.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
#!/bin/bash
2-
echo "Enter The Number"
3-
read n
4-
num=$(expr $n % 2)
5-
if [ $num -eq 0 ]; then
1+
#!/usr/bin/env bash
2+
echo -n "Enter The Number: "
3+
read -r n
4+
if [ $((n % 2)) -eq 0 ]; then
65
echo "is a Even Number"
76
else
87
echo "is a Odd Number"

scripts/factorial.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#!/bin/bash
2-
echo "Enter The Number"
3-
read a
1+
#!/usr/bin/env bash
2+
echo -n "Enter The Number: "
3+
read -r a
44
fact=1
5-
while [ $a -ne 0 ]; do
6-
fact=$(expr $fact \* $a)
7-
a=$(expr $a - 1)
5+
while [ "$a" -ne 0 ]; do
6+
fact=$((fact * a))
7+
a=$((a - 1))
88
done
99
echo $fact

scripts/fibonacci.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
#!/bin/bash
2-
x=0
3-
y=1
4-
i=2
5-
while true ; do
6-
i=$(expr $i + 1)
7-
z=$(expr $x + $y)
1+
#!/usr/bin/env bash
2+
3+
x=0; y=1; i=2
4+
while true; do
5+
i=$((i + 1))
6+
z=$((x + y))
87
echo -n "$z "
98
x=$y
109
y=$z

scripts/hello-world.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
#!/bin/bash
2-
3-
echo "Hello World !"
1+
#!/usr/bin/env bash
2+
echo "Hello World!"

scripts/hextodec.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 "%d \n " $1
1+
#!/usr/bin/env bash
2+
printf "%d\n " "$1"

scripts/list-dir.sh

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

3-
list=($(ls))
3+
set -- *
44

5-
for f in "${list[@]}";do
6-
echo $f
7-
done
5+
for i; do
6+
echo "$i"
7+
done

scripts/lowercase.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
2-
read -p "Enter String Uppercase : " i
3-
o=$(echo "$i" | tr '[:upper:]' '[:lower:]')
4-
echo $o
1+
#!/usr/bin/env bash
2+
echo -n "Enter String Uppercase: "
3+
read -r i
4+
echo "$i" | tr '[:upper:]' '[:lower:]'

scripts/multiplication.sh

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

scripts/prime.sh

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
#!/bin/bash
2-
echo “Enter Any Number”
3-
read n
4-
i=1
5-
c=1
6-
while [ $i -le $n ]; do
7-
i=$(expr $i + 1)
8-
r=$(expr $n % $i)
9-
if [ $r -eq 0 ]; then
10-
c=$(expr $c + 1)
11-
fi
1+
#!/usr/bin/env bash
2+
echo -n "Enter Any Number: "
3+
read -r n
4+
i=1; c=1
5+
while [ $i -le "$n" ]; do
6+
i=$((i + 1))
7+
r=$((n % i))
8+
[ $r -eq 0 ] && c=$((c + 1))
129
done
10+
1311
if [ $c -eq 2 ]; then
14-
echo Prime
12+
echo "Prime"
1513
else
16-
echo Not Prime
14+
echo "Not Prime"
1715
fi

scripts/process.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#! /bin/bash
1+
#!/usr/bin/env bash
22
echo "Hello $USER"
3-
echo "Hey i am" $USER "and will be telling you about the current processes"
3+
echo "Hey i am $USER and will be telling you about the current processes"
44
echo "Running processes List"
55
ps

scripts/random-emoji.sh

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

33
while true; do
44
rand=$(shuf -i 2600-2700 -n 1)
5-
echo -n -e ' \u'$rand
5+
echo -en " \u$rand"
66
sleep 1
77
done

scripts/randomfile.sh

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

33
echo "Hello $USER"
4-
echo "$(uptime)" >>"$(date)".txt
4+
uptime >> "$(date)".txt
55
echo "Your File is being saved to $(pwd)"

scripts/rang-random.sh

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

3-
shuf -i $1-$2 -n 1
3+
shuf -i "$1-$2" -n 1

0 commit comments

Comments
 (0)