More Shell problems

Giorgos Keramidas keramida at ceid.upatras.gr
Mon Mar 24 03:45:04 EET 2003


On 2003-03-23 16:04, Nicolas Greece <nicolas26 at yahoo.com> wrote:
> Kalimera se olous kai pali. Meta apo ena SK sklirou
> diavasmatos, erxomai me perissoteres apories...

Heh :)

> 1.
> sto Home otan dino (ls |sort) ginete kanonika sort
> alla otan kano ls | sort  /home/Nicolas/Lab/ mou leei
> oti einai directory

Pernas to directory san parametro sto sort ki oxi sto ls.
Dokimase kalutera:

	ls -l /home/Nicolas/Lab | sort

h akoma kalutera koita sto manpage ths ls gia na deis mhpos kapoio apo
ta sorting options pou exei sou kanei.

----------------------------------------------------------------------------

> Pos boro
> a) na kano sort directories

An ennoeis na sou deixnei to output ths ls mono oti einai directory,
tote des ligo ti kanei to ejhs:

	ls -l | grep '^d' | sort

> b) na kano sort arxeia mesa se directories (opos thelo pio pano?)

To anapodo apo to paranapw (dhladh mia sorted lista apo ola osa DEN
einai directories) einai peripou to idio, me monh diafora thn
parametro -v sto grep:

	ls -l | grep -v '^d' | sort

----------------------------------------------------------------------------

> 2.
> Ftiaxno ena script me arguments arg1, arg2, arg3, klp...
> Dino /home/nicolas/arg Nikos Nikolaou ilias kai doulevei
>
> Otan pao na to kano output na sothei den tha prepei na tou doso
> /home/nicolas/arg Nikos Nikolaou ilias -o /home/nicolas/name.txt?
>
> Giati kai edo den benei sto arxei pou thelo?

Giati na mpei?  To script sou kanei kati idiaitero gia na katalabei
oti tou perases thn parametro -o?

An thes na kaneis anakateu8unsh tou output se script, to mono sigouro
einai me ta > kai < operators tou shell sou:

	script arg1 arg2 arg3 <inputfile

	script arg1 arg2 arg3 >outputfile

	script arg1 arg2 arg3 <inputfile >outputfile

klp.

----------------------------------------------------------------------------

> 3.
> a) Sta shell Variables gia to csh einai
>    Set my_string1="Hallo" (gia string)
>    gia to bash?
>
> b) Sta shell Variables gia to csh einai @ x=7
>    (alfarithmitiko)
>    gia to bash?

Diabase to manpage tou kathe shell.  H akoma kalutera, prospathise na
breis kapoio kalo biblio gia eisagogh se shell scripting.  Ena klasiko
(alla ligo strufno gia arxarious biblio) einai to

	"The Unix Programming Environment" tou Rob Pike.

Auto pou thes einai na matheis pos douleuounn oi metablhtes se Bourne
kai csh typou shells.  Yparxoun 2 eidh metablhtwn, kai to kathe shell
exei diko tou suntaktiko gia to kathe eidos.

Gia paradeigma... sto csh, dokimase ta ejhs:

	$ /bin/csh
	csh> set myname = 'Giorgos'

	csh> echo "$myname"
	Giorgos

	csh> csh -c 'echo "$myname"'
	myname: Undefined variable.

	csh> unset myname

	csh> setenv myname 'Giorgos'

	csh> csh -c 'echo "$myname"'
	Giorgos

	csh> _

Diabazontas to manual page tou csh thelo na mou peis (san askhsh)
giati thn proth fora pou etreksa

	csh -c 'echo "$myname"'

den doulepse kai mou eipe `myname: Undefined variable.', enw th
deuterh epaikse mia xara kai mou tupose to onoma mou.  Epishs thelo na
mou peis poia einai h pio shmantikh diafora sto suntaktiko ths entolhs
'set' apo th 'setenv'.

An to kaneis auto, tote exeis mathei ola osa xreiazetai na ksereis gia
to pos ginontai set oi shell variables se csh.

Meta tha poume kai gia bash :-)

----------------------------------------------------------------------------

> 4.

> Prospatho me tin make command. ftiaxno ena fakelo makefile pou
> periexei ta ekseis gia na xrisimopoio to make kai na ta kanei
> aftomata...
>
> greetings.class: greetings.java
>
> javac greetings.java
>
> Kai mou vgaze:makefile:1 *** missing seperator.
> stop...
>
> Enoeitai kai exo ftiaksei to greetings.java...

To suntaktiko enos Makefile einai austhro, kai den epitrepetai na
bazeis kenes grammes opou sou katebei.  Giati meta thn proth grammh
afhses mia kenh?

Epishs, otan grafeis entoles gia ena `target' (opws parapanw to
greetings.class) oi entoles pou grafeis gia na `xtiseis' to target
prepei na exoun sthn arxh ena h perissotera TAB.

	PROSOXH, OXI SPACES, ALLA TAB !!!

Bazontas ta ola mazi, dokimase na ftiakseis ena Makefile pou na exei
ta ejhs (ola ta indentation levels einai me TAB):

	greetings.class: greetings.java
		javac greetings.java

> 5.
> exei parousiastei ena arxeio me onoma #greetings# kai me rm den
> svinei. Ti einai afto to arxeio kai giati ginete afto?

To pio pithano einai na to eftiakse kapoio editor pou xrhsimopoieis,
san backup file.  PRIN TO SBHSEIS... des ti exei mesa:

	more '#greetings#'

Ta apla quotes exoun shmasia.  Mhn ta paraleipseis.

> 6.
> Kanena vivliaraki kainourio eiparxei se sxesi me afta pou asxoloume?
> Exo idi parei (proxtes) to Unix in a nutshell alla me mathimata kai
> paradeigmata as poume...

Nai ame, para polla.  Me ti akribos asxoleisai?  Ta biblia einai para
polla gia na katso na grapso se ena mail ola ta onomata tous.  An peis
kapoio sugkekrimeno thema, kati ginetai...

- Giorgos




More information about the Linux-greek-users mailing list