Linux Shellscript Tutorial

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Linux Shellscript Tutorial as PDF for free.

More details

  • Words: 906
  • Pages: 11
:

- 2005-2006 -

shell scripts ; shell script .

shellscipt : #!/bin/bash (bash). ! test.sh :

! " #!/bin/bash E#mkdir test cp .login test echo “h antigrafh egine”

755

# $ ! root ./test.sh

:

test .login : H antigrafh egine

! "

test

:

$

: % "

! . . X=”abc” . echo $X . &

" :

#!/bin/bash $'=“ABC” Eecho “$X” # kalo einai ean prokeitai gia metavlith keimenoy na x#xrhshmopoiounatai eisagwgika ABC .

%

echo

( "

. &

echo –e :

To \n \t " To \b To echo –e “12\t3\n456\b” 12 45

3

tab backspace ! :

K

"

"

": ! #!/bin/bash echo "Gia sou , $USER. Tha sou kanw mia lista me ta arxeia sou" echo "Sou kanw lista me ta arxeia tou fakelou, $PWD" ls $USER

%

.

$PWD

:

)

System Variable BASH=/bin/bash BASH_VERSION ( HOME PATH=/usr/bin:/sbin:/bin:/usr/sbin * PWD

Meaning shell ! shell home directory !

) !

SHELL=/bin/bash USERNAME

shell " ! !

O "

:

! #!/bin/bash $#=”ls” $B=”-l” echo “$# $+ *.exe" #

!

: ls –l *.exe

: : metavlhth="$(entolh)"

x=”$(ls)

ls. redirect ls

. $ls>test.txt

test.txt.,

! ! !

.

-

: $ls>>.login.

, "

! $

!

"

input

: $cat>test.txt. ! " $

redirect : $ tr "[a-z]" "[A-Z]" < >megala_grammata.txt !

mikra_grammata.txt mikra_grammata.txt, megala_grammata.txt

output

"

! .

If…fi , :

$ if synthikh1 then endoles .......... elif synthikh2 then endoles ........ elif synthikh3 then endoles ........ fi

$

"

" : … -n

)

-z

)

-s

&

-f (file)

.

-d

.

(

) !

(

)

!

!

!

(directory) -w

,

-r

&

-x

&

-d

.

-f

.

-eq

)

/ !

! !

-neq

equal

=

)

!=

#

-lt

)

1

-gt

)

1

-ge

)

1

-le

)

1

!

0

NOT

-a

0

AND

-o

0

OR

=

" :

& !

1

#!/bin/bash X="" if [ -n "$X" ]; then # to -n elenxei ean to x den exei mhdeniko megethos echo "To X den einai keno" else echo “To x einai keno” fi

“To x einai keno”

# 2

!

#!/bin/bash read X read Y if [ $X –nq $Y ] ; then echo "X aniso toy Y" fi

#

'=1

“X aniso toy Y”

.=2

(loops) ,

/ . .

$

!

/ "

For loops )

/

for

"

$

for X in (kapoia stoixeia) do entoles done !

1

#!/bin/bash colour1="red" colour2="light blue" colour3="dark green" for X in "$colour1" $colour2" $colour3" do echo “$X ,” done

: red , light blue , dark green

# !

2

#!/bin/bash for X in *.tar do gzip $X done

#

tar

:

! :

&

$

$

:

for (( arxikh timh; Synthikh ; apotelesma )) do entoles pou epanalambanontai Done

! #!/bin/bash for (( i = 0 ; do echo $i done

i <= 5;

i = i + 1

"

))

i

"

0

5 1.

-

" 1

! "

20.

While loops (

:

$

while [ isxyei h synthikh ] do entoles done

! #!/bin/bash X=0 while [ $X -le 20 ] do echo $X X=$((X+1)) done

1

#

, Onoma_synarthshs ( ) { entoles return

"

:

20

}

1 . ,

!

: Onoma_synarthshs. ! #!/bin/bash $ SayHello() { echo "Hello $LOGNAME, Have nice computing" return } $ SayHello()

'

:

"

: test.txt

Nikos Kostas Maria Eleni

!

1 2 3 4 $cut –f1 test.txt ! $cut –f2

1 1 2

test.txt

test.txt

-

:

.

:

India's milk is good. tea Red-Lable is good. tea is better than the coffee. $ sed '/tea/s//milk/g' teaormilk

! :

/tmp/result.tmp.$$

To /tea/ , $

>

s//milk

g (global)

!

. /tmp/result.tmp.$$ .

ex $ ex onoma_arxeiou

,

. "

" .

"

&

: p :

( , , ,

2

:2 p

. 2

:2,5 p

5

.

2

:2,$ p

. :set number :2 p

,

. d :

(

2

:2 d

, ,

. 2

:2,5 d

5

.

co :

(

1

:1,4 co

,

4

"

. H

/ $ :/linux/p

, $ ,

:

$

linux. :g/linux/p

$

linux.

(

:w

.

(

:q

ex.

! Shell

script ! terminal. cd " ! ! :

# .rmp

# mount /mnt/cdrom # cd /mnt/cdrom/RedHat/RPMS # rpm -ivh dialog-0.6-16.i386.rpm

" : Message dialog --title "titlos" --backtitle "sxolio grammi 1\ allagh grammhs. . . " 7 50 ; read

Msg box dialog --title "titlos" --backtitle "sxolio… " 9 50

Yes/no dialog dialog --title "Titlos" --backtitle "sxolio" 7 60 sel=$? case $sel in 0) echo "H apanthsh einai nai";; 1) echo "H apantish einai oxi";; 255) echo "O xristis pathse esc";; esac

Input dialog --title "titlos" --backtitle "sxolio" --inputbox "Edw grafoume" 8 60 2>/tmp/input.$$ #me ayto kleinoyme to dialogo sel=$? na=`cat /tmp/input.$$` case $sel in 0) echo "H metavlith pou phrame $na" ;;

$

1) echo "paththike cancel" ;; 255) echo "paththike esc" ;; esac rm -f /tmp/input.$$

Select dialog --backtitle "titlos " --title "titlos menu" --menu "sxolio epilogwn" 15 50 3\ epilogh1 "sxolio"\ epilogh2 " sxolio "\ epilogh3 "sxolio" 2>/tmp/menuitem.$$ menuitem=`cat /tmp/menuitem.$$` opt=$? case $menuitem epilogh1) echo epilogh2) echo epilogh3) echo esac

in “epilexthike to 1”;; “epilexthike to 2”;; “epilexthike to 1”;;

$

" !

!

!

chmod +x arxeio

#

" sh [options] file

,

:

" -v -x

! shell script.

"

input.

:

Related Documents

Tutorial Linux
June 2020 5
Shellscript-day1
October 2019 27
Shellscript-day2
October 2019 15
Linux Tutorial 1
November 2019 4