Skip to content

Instantly share code, notes, and snippets.

@ahmedsayedabdelsalam
Created December 26, 2020 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmedsayedabdelsalam/4818c9d01a594e28ed277423b332dc8c to your computer and use it in GitHub Desktop.
Save ahmedsayedabdelsalam/4818c9d01a594e28ed277423b332dc8c to your computer and use it in GitHub Desktop.
#! /bin/bash
#####################################################
echo "abdelsalam" >> file.txt
#####################################################
#####################################################
: '
ahmed
sayed
abdelsalam
'
#####################################################
#####################################################
cat << creative
ahmed sayed abdelsalam
hassan ahmed mostafa
mousa sayed ahmed
creative
#####################################################
#####################################################
count=9
# if [ $count -ne 9 ]
if (( $count != 9 ))
then
echo "the condition is true"
elif (($count == 9))
then
echo "the condition"
else
echo "the condition is false"
fi
#####################################################
#####################################################
age=30
#and => && , -a
#or => || , -o
# if (( $age > 10 )) && (( "$age" < 40 ))
if (( "$age" > 10 && $age < 40 ))
# if [ "$age" -gt 10 ] && [ $age -lt 40 ]
# if [[ "$age" -gt 10 && $age -lt 40 ]]
# if [ "$age" -gt 10 -a $age -lt 40 ]
then
echo "age is correct"
else
echo "age is not correct"
fi
#####################################################
#####################################################
car=s1
case $car in
"BMW" )
echo "it's BMW" ;;
"MERCEDESE" )
echo "it's MERCEDESE" ;;
"HONDA" )
echo "it's HONDA" ;;
* )
echo "unknown car name" ;;
esac
#####################################################
#####################################################
number=1
while [ $number -le 10 ]
do
echo $number
number=$((number+1))
done
#####################################################
#####################################################
number=1
until [ $number -ge 10 ]
do
echo $number
number=$((number+1))
done
#####################################################
#####################################################
# for i in 1 2 3 4 5
for ((i=0; i<10; i++))
do
if [ $i -gt 5 ]
then
#continue
break
fi
echo $i
done
#####################################################
#####################################################
echo $0 $1 $2 $3
#####################################################
#####################################################
args=($@)
# echo ${args[0]} ${args[1]} ${args[2]}
echo $@
echo $#
#####################################################
#####################################################
while read line
do
echo $line
done < ${1:-/dev/stdin}
#####################################################
#####################################################
ls -la > file.txt
ls +la > file.txt 2> error.txt
# ls +la > file.txt 2>&1
ls +la >& file.txt
#####################################################
#####################################################
MESSAGE="Hello from helloScript"
export MESSAGE
./secondScript.sh
#####################################################
#####################################################
echo "enter 1st string"
read s1
echo "enter 2nd string"
read s2
if [ $s1 == $s2 ]
then
echo "strings match"
else
echo "strings don't match"
fi
if [ $s1 \> $s2 ]
then
echo "string 1 is larger"
elif [ $s1 \< $s2 ]
then
echo "string 2 is larager"
else
echo "both are equal"
fi
c=$s1$s2
echo $c
# echo ${s1^}
# echo ${s2^^}
#####################################################
#####################################################
n1=4
n2=20
echo $(( n1+n2 ))
echo $(( n1-n2 ))
echo $(( n1*n2 ))
echo $(( n1/n2 ))
echo $(( n1%n2 ))
echo $(expr $n1 + $n2)
echo $(expr $n1 - $n2)
echo $(expr $n1 \* $n2)
echo $(expr $n1 / $n2)
echo $(expr $n1 % $n2)
#####################################################
#####################################################
echo "enter hex number of your choice"
read Hex
echo -n "the decimal value of $Hex is : "
echo "obase=10; ibase=16; $Hex" | bc
#####################################################
#####################################################
declare myvar=ahmed
echo $myvar
myvar=sayed
echo $myvar
declare -r mynewvar=readonly
echo $mynewvar
mynewvar=hello
echo $mynewvar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment