Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9949851

Browse files
Add files via upload
1 parent bff6e51 commit 9949851

35 files changed

+613
-0
lines changed

‎Bash-Arithmetic.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Author : Jaydatt Patel
2+
# arithmetic : +,-,*,/,%
3+
#syntax : $((arithmetic))
4+
5+
echo $((5+2))
6+
echo $((5-2))
7+
echo $((5*2))
8+
echo $((5/2))
9+
echo $((5%2))
10+
11+
a=7
12+
b=3
13+
echo $((a+b))
14+
15+

‎Bash-Array.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Author : Jaydatt Patel
2+
# Method-1 : declare -a Array_name
3+
# Method-2 : arr=()
4+
# Method-3 : array_name=(1 2 "three" $num.......)
5+
# echo ${arr[pos]} for selected elements
6+
# echo ${arr[@]} for all elements
7+
8+
9+
# arr=() Create an empty array
10+
# arr=(1 2 3) Initialize array
11+
# ${arr[2]} Retrieve third element
12+
# ${arr[@]} Retrieve all elements
13+
# ${!arr[@]} Retrieve array indices
14+
# ${#arr[@]} Calculate array size
15+
# arr[0]=3 Overwrite 1st element
16+
# arr+=(4) Append value(s)
17+
# str=$(ls) Save ls output as a string
18+
# arr=( $(ls) ) Save ls output as an array of files
19+
# ${arr[@]:s:n} Retrieve n elements starting at index s
20+
21+
# Method-1
22+
declare -a emptyArr #create empty array
23+
echo ${emptyArr[@]}
24+
25+
# Method-2
26+
empArr=()
27+
28+
# Method-3
29+
num=5
30+
arr=(1 2 "three" "four" $num)
31+
arr+=("six")
32+
arr+=(7)
33+
34+
echo Array Size : ${#arr[@]}
35+
36+
echo ${arr[0]}
37+
echo ${arr[2]}
38+
echo ${arr[@]}
39+
40+
echo "for loop 1:"
41+
for item in ${arr[@]}
42+
do
43+
echo $item
44+
done
45+
46+
echo "for loop 2:"
47+
for i in ${!arr[@]}; do
48+
echo "element $i is ${arr[$i]}"
49+
done
50+
51+
echo "\${arr[@]:2} : "${arr[@]:2}
52+
echo "\${arr[@]:2:3} : "${arr[@]:2:3}

‎Bash-For-Loop.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Author : Jaydatt Patel
2+
for ((i=0; i<10; i++))
3+
do
4+
echo val : $i
5+
if [ $i -gt 5 ]
6+
then
7+
break
8+
fi
9+
done

‎Bash-If-elif-else-fi.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# if [ exp ] && [ exp ] || [ exp ]...
2+
# then
3+
# .....
4+
# elif [ exp ] && [ exp ] || [ exp ]...
5+
# then
6+
# ....
7+
# else
8+
# .....
9+
# fi
10+
# Author : Jaydatt Patel
11+
#
12+
# exp : [ v1 -lt v2 ] && [ v1 -eq v2 ] || [ v1 -gt v2 ]
13+
# -lt : less than
14+
# -eq : equl to
15+
# -gt : greater than
16+
17+
num=5
18+
if [ $num -lt 0 ]
19+
then
20+
echo "Negative"
21+
elif [ $num -gt 0 ]
22+
then
23+
echo "Positive"
24+
else
25+
echo "Neutral"
26+
fi
27+
28+
29+
30+
ss="B"
31+
if [ $ss == "A" ]
32+
then
33+
echo "Apple"
34+
elif [ $ss == "B" ]
35+
then
36+
echo "Ball"
37+
else
38+
echo "Invalid"
39+
fi

‎Bash-Methcharacters.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Author : Jaydatt Patel
2+
# '#' for comment
3+
# echo "comment"
4+
5+
# "\" to write script in mutiple lines
6+
echo \
7+
"Hello" \
8+
"World"
9+
10+
# ";" for command seperator
11+
echo "Hello"; echo "World"
12+
13+
# "*" for string expansion wildcard
14+
ls /bin/ba* # list all files or folders which start from 'ba'
15+
ls *.txt
16+
17+
18+
# "?" for single character expansion wildcard
19+
ls /bin/?ash # list all files or folders which has 4 char name and ending with 'ash'
20+
ls file2013-02-??.txt

‎Bash-String.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Author : Jaydatt Patel
2+
# tr to translate or replace character
3+
echo "Linux and shell scripting are awesome" | tr "aeiou" "_" # replace characters in string where char are a,e,i,o,u
4+
echo "Linux and shell scripting are awesome" | tr -c "aeiou" "_" # repalce other character in string ignoring a,e,i,o,u
5+
6+
echo "Linux and shell scripting are awesome" | tr "[a-z]" "[A-Z]" # repalce charaters
7+
8+
9+
ss="Hello"
10+
# "\" escape with
11+
# interpret literal and evalute metachar with " " double coats
12+
echo "$ss World" # Out : Hello World
13+
echo "\$ss World" # Out : $ss World
14+
15+
# escape all metacharacters with ' ' single coats
16+
echo '$ss World' # Out : $ss World
17+
echo '\$ss World' # Out : \$ss World

‎Bash-While-Loop.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Author : Jaydatt Patel
2+
# while [ exp ] && [ exp ] || [ exp ]...
3+
# do
4+
# ...
5+
# done
6+
# exp : [ v1 -lt v2 ] && [ v1 -eq v2 ] || [ v1 -gt v2 ]
7+
# -lt : less than
8+
# -eq : equl to
9+
# -gt : greater than
10+
11+
num=0
12+
while [ $num -lt 10 ]
13+
do
14+
echo val : $num
15+
if [ $num -gt 5 ]
16+
then
17+
break
18+
fi
19+
((num++))
20+
done

‎Bash-pipe-prarallel-sequence.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Author : Jaydatt Patel
2+
# run command piping [command] | [command] | ......
3+
sort animal.txt | uniq
4+
sort animal.txt | uniq | tr "[a-z]" "[A-Z]"
5+
6+
# multiple line piping
7+
cat animal.txt |\
8+
uniq |\
9+
tr "[a-z]" "[A-Z]"
10+
11+
12+
# Run Sequencially each command
13+
echo "Sequencial :"
14+
echo "AA" ; echo "BB" ; echo "CC" ; echo "DD" ;
15+
echo "EE"
16+
17+
# Run Prallel each command
18+
echo "Parallel :"
19+
echo "A" & echo "B" & echo "C" &\
20+
echo "D" &\
21+
echo "E"

‎Bash-variables-read-export.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Author : Jaydatt Patel
2+
# get bash path location
3+
which bash
4+
bashPath=`which bash`
5+
echo bashPath
6+
7+
# variable
8+
a=10
9+
b=15.5
10+
c=$((a+b))
11+
d=$c
12+
s1="String"
13+
echo ${a} ${b} ${c} ${d}
14+
15+
# set to get all shell variables
16+
set
17+
18+
# unset to delete variables
19+
unset a
20+
unset b c
21+
22+
# env to list all environment variables
23+
env
24+
25+
# read to read data from user
26+
a=0
27+
read a
28+
29+
# export variable to child process
30+
export x
31+
export y=5
32+

‎Data-cat-head-tail-wc.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Author : Jaydatt Patel
2+
# cat for get file data
3+
echo "Get data : "
4+
cat age.txt
5+
cat animal.txt
6+
7+
# head -n to get first n lines
8+
head -3 animal.txt
9+
10+
# tail -n to get last n lines
11+
tail -3 animal.txt
12+
13+
# wc to get number of lines, words counts and characters counts of files
14+
wc animal.txt
15+
wc -l animal.txt # to get line counts
16+
wc -w animal.txt # to get words count
17+
wc -c animal.txt # to get character counts
18+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /