Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Community > Tech > [Misteri] -e si nasconde
Pages (5): « 1 [2] 3 4 5 »   Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
Alf
°o.mini sayan.o°

User info:
Registered: Jun 2003
Posts: 5381 (0.65 al dì)
Location: Mediolanum
Corso: Informatica
Anno: FINITOOOO!
Time Online: 155 Days, 9:46:05: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Ah ultima cosa lally se il problema e' proprio "stampare SOLO -e " ho una soluzione anche se non e' il massimo :)

__________________
(\ /)
( . .)
c('')('') This is Bunny!
Help her succeed in world domination by copy and pasting her in
your signature.

26-08-2005 14:36
Click Here to See the Profile for Alf Click Here to See the Blog of Alf Click here to Send Alf a Private Message Find more posts by Alf Add Alf to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
lallyblue
.grande:maestro.

User info:
Registered: Sep 2002
Posts: 2868 (0.34 al dì)
Location: un puntino nello spazio infinito
Corso: Informatica
Anno: ZERO!
Time Online: 29 Days, 9:48:21 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

tipo?

io semplicemente facevo un
if echo $variabile | grep <regexp>
then
command
else
command
fi

boh mi sembrava la soluzione +semplice... :\

si può adattare?

__________________
*** Proposta di legge di iniziativa popolare: "8x1000 ALLA RICERCA"
Informati e firma la petizione! E' nel tuo interesse! ;)

*** Browse my dA gallery ! ;)
***In medio stat virtus

26-08-2005 14:39
Click Here to See the Profile for lallyblue Click Here to See the Blog of lallyblue Click here to Send lallyblue a Private Message Visit lallyblue's homepage! Find more posts by lallyblue Add lallyblue to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Alf
°o.mini sayan.o°

User info:
Registered: Jun 2003
Posts: 5381 (0.65 al dì)
Location: Mediolanum
Corso: Informatica
Anno: FINITOOOO!
Time Online: 155 Days, 9:46:05: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by lallyblue
tipo?

io semplicemente facevo un
if echo $variabile | grep <regexp>
then
command
else
command
fi

boh mi sembrava la soluzione +semplice... :\

si può adattare?


con il case:


case "$variabile" in

"-e"|"-q"|"-u"|"-uq")
command1
command2
;;

*)
command3

;;
esac


Se il valore $variabile si trova fra -e -q -u -uq esegue i comandi command1 command2 in tutti gli altri casi (*) esegue command 3


per STAMPARE -e fai cosi' ...

echo \"-e\" | cut -c2,3


Non e' bellissimo ... ma funziona :)

__________________
(\ /)
( . .)
c('')('') This is Bunny!
Help her succeed in world domination by copy and pasting her in
your signature.

26-08-2005 14:43
Click Here to See the Profile for Alf Click Here to See the Blog of Alf Click here to Send Alf a Private Message Find more posts by Alf Add Alf to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DeepBlue
tired guy

User info:
Registered: Sep 2003
Posts: 4258 (0.52 al dì)
Location: CSN
Corso: Info tlc
Anno:
Time Online: 52 Days, 8:40:31 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by ak47
la RE che soddisfa la tua richiesta è [-e|-q|-ue|-uq]


in bash con *grep mi sa che così non funziona.

Meglio che passi tutto a egrep così:

code:
egrep "(^-)(e|q|ue|uq)"


Per il problema del -e..boh?

edit: anche io avevo pensato ad una soluzione simile a quella di alf (per l'assegnamento di -e) e mi sa che è l'unica strada, a meno di sostituire -e con qualcosaltro :D:D:D

__________________
~ get Debian! ~ get FreeBSD! ~ get OpenBSD! ~

Last edited by DeepBlue on 26-08-2005 at 14:57

26-08-2005 14:45
Click Here to See the Profile for DeepBlue Click Here to See the Blog of DeepBlue Click here to Send DeepBlue a Private Message Find more posts by DeepBlue Add DeepBlue to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
lallyblue
.grande:maestro.

User info:
Registered: Sep 2002
Posts: 2868 (0.34 al dì)
Location: un puntino nello spazio infinito
Corso: Informatica
Anno: ZERO!
Time Online: 29 Days, 9:48:21 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

l'opzione purtroppo non posso cambiarla, è quella che devo passare ad un programma x avere un certo risultato.
a questo punto userò l'egrep che mi hai suggerito, solo mi suonava strano che un comando come echo avesse tali limitazioni...
non c'è un comando alternativo all'echo x mostrare il contenuto delle variabili, vero?

__________________
*** Proposta di legge di iniziativa popolare: "8x1000 ALLA RICERCA"
Informati e firma la petizione! E' nel tuo interesse! ;)

*** Browse my dA gallery ! ;)
***In medio stat virtus

26-08-2005 14:59
Click Here to See the Profile for lallyblue Click Here to See the Blog of lallyblue Click here to Send lallyblue a Private Message Visit lallyblue's homepage! Find more posts by lallyblue Add lallyblue to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Alf
°o.mini sayan.o°

User info:
Registered: Jun 2003
Posts: 5381 (0.65 al dì)
Location: Mediolanum
Corso: Informatica
Anno: FINITOOOO!
Time Online: 155 Days, 9:46:05: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by DeepBlue
in bash con *grep mi sa che così non funziona.

Meglio che passi tutto a egrep così:

code:
egrep "(^-)(e|q|ue|uq)"


Per il problema del -e..boh?

edit: anche io avevo pensato ad una soluzione simile a quella di alf (per l'assegnamento di -e) e mi sa che è l'unica strada, a meno di sostituire -e con qualcosaltro :D:D:D


ma scusa ... fare un if in pipe a un egrep e' simulare un case ... O_o;; perche' simularlo quando c'e' ?! :)

__________________
(\ /)
( . .)
c('')('') This is Bunny!
Help her succeed in world domination by copy and pasting her in
your signature.

26-08-2005 15:06
Click Here to See the Profile for Alf Click Here to See the Blog of Alf Click here to Send Alf a Private Message Find more posts by Alf Add Alf to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
lallyblue
.grande:maestro.

User info:
Registered: Sep 2002
Posts: 2868 (0.34 al dì)
Location: un puntino nello spazio infinito
Corso: Informatica
Anno: ZERO!
Time Online: 29 Days, 9:48:21 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

beh perché di solito il case lo applico quando ho tante opzioni e diventerebbe difficile usare tanti if/then/else in cascata. visto che qui o l'opzione è tra quelle 4 (e allora esegue il comando) oppure è qualsiasi altra cosa (e allora stampa un mex d'errore) mi sembrava + logico usare un if/then/else... ma non sono una buona programmatrice quindi è facile che mi sbagli... ;)

__________________
*** Proposta di legge di iniziativa popolare: "8x1000 ALLA RICERCA"
Informati e firma la petizione! E' nel tuo interesse! ;)

*** Browse my dA gallery ! ;)
***In medio stat virtus

26-08-2005 15:11
Click Here to See the Profile for lallyblue Click Here to See the Blog of lallyblue Click here to Send lallyblue a Private Message Visit lallyblue's homepage! Find more posts by lallyblue Add lallyblue to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DeepBlue
tired guy

User info:
Registered: Sep 2003
Posts: 4258 (0.52 al dì)
Location: CSN
Corso: Info tlc
Anno:
Time Online: 52 Days, 8:40:31 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by lallyblue
non c'è un comando alternativo all'echo x mostrare il contenuto delle variabili, vero?

ho paura di no :/

Originally posted by Alf
ma scusa ... fare un if in pipe a un egrep e' simulare un case ... O_o;; perche' simularlo quando c'e' ?!

E che ne so io? :D
Lally era partita dicendo che stava usando grep ed egrep, io non sapendo su cosa stesse lavorando, mi sono adeguato :D

__________________
~ get Debian! ~ get FreeBSD! ~ get OpenBSD! ~

26-08-2005 15:14
Click Here to See the Profile for DeepBlue Click Here to See the Blog of DeepBlue Click here to Send DeepBlue a Private Message Find more posts by DeepBlue Add DeepBlue to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Alf
°o.mini sayan.o°

User info:
Registered: Jun 2003
Posts: 5381 (0.65 al dì)
Location: Mediolanum
Corso: Informatica
Anno: FINITOOOO!
Time Online: 155 Days, 9:46:05: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by lallyblue
beh perché di solito il case lo applico quando ho tante opzioni e diventerebbe difficile usare tanti if/then/else in cascata. visto che qui o l'opzione è tra quelle 4 (e allora esegue il comando) oppure è qualsiasi altra cosa (e allora stampa un mex d'errore) mi sembrava + logico usare un if/then/else... ma non sono una buona programmatrice quindi è facile che mi sbagli... ;)


Beh sono equivalenti alla fine.

E cmq questo e' il caso in cui hai piu' scelte .. il fatto che 4 scelte facciano fare la stessa azione e' irrilevante :)

Cmq dentro l'if devi richiamare il grep :)

Il case lo fa da solo il parsing

Cmq alla fine sta a te decidere ;)



Ci sono altri comandi al posto dell'echo ma danno tutti lo stesso problema

Printf per esempio :)

__________________
(\ /)
( . .)
c('')('') This is Bunny!
Help her succeed in world domination by copy and pasting her in
your signature.

26-08-2005 15:28
Click Here to See the Profile for Alf Click Here to See the Blog of Alf Click here to Send Alf a Private Message Find more posts by Alf Add Alf to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
lallyblue
.grande:maestro.

User info:
Registered: Sep 2002
Posts: 2868 (0.34 al dì)
Location: un puntino nello spazio infinito
Corso: Informatica
Anno: ZERO!
Time Online: 29 Days, 9:48:21 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

fico... :roll:

grazie mille cmq!

__________________
*** Proposta di legge di iniziativa popolare: "8x1000 ALLA RICERCA"
Informati e firma la petizione! E' nel tuo interesse! ;)

*** Browse my dA gallery ! ;)
***In medio stat virtus

26-08-2005 16:17
Click Here to See the Profile for lallyblue Click Here to See the Blog of lallyblue Click here to Send lallyblue a Private Message Visit lallyblue's homepage! Find more posts by lallyblue Add lallyblue to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Alf
°o.mini sayan.o°

User info:
Registered: Jun 2003
Posts: 5381 (0.65 al dì)
Location: Mediolanum
Corso: Informatica
Anno: FINITOOOO!
Time Online: 155 Days, 9:46:05: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by lallyblue
fico... :roll:

grazie mille cmq!


Anzi no ..
Ti ho trovato la soluzione

code:
pippo=-e printf "%s\n" $pippo


Cosi' stampa tutto cio' che vuoi :D

__________________
(\ /)
( . .)
c('')('') This is Bunny!
Help her succeed in world domination by copy and pasting her in
your signature.

26-08-2005 16:34
Click Here to See the Profile for Alf Click Here to See the Blog of Alf Click here to Send Alf a Private Message Find more posts by Alf Add Alf to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DeepBlue
tired guy

User info:
Registered: Sep 2003
Posts: 4258 (0.52 al dì)
Location: CSN
Corso: Info tlc
Anno:
Time Online: 52 Days, 8:40:31 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

grande Alf :D

__________________
~ get Debian! ~ get FreeBSD! ~ get OpenBSD! ~

26-08-2005 17:20
Click Here to See the Profile for DeepBlue Click Here to See the Blog of DeepBlue Click here to Send DeepBlue a Private Message Find more posts by DeepBlue Add DeepBlue to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Viry
dsy moderator

User info:
Registered: Oct 2002
Posts: 2429 (0.29 al dì)
Location: Milano
Corso: Ticom
Anno: primo
Time Online: 43 Days, 3:27:12 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Senza diventare matti, c'e' getopts per fare cio':
Nell'esempio lo script accetta le opzioni -h -a -b -c

code:
while getopts "habc" opt; do case $opt in h ) visualizzo_help ;; a) eseguo_una_cosa;; b ) faccio_altra_cosa;; .... esac done

Molto piu' comodo, no?
Qui la man page:
http://www.ss64.com/bash/getopts.html
e un po' di esempietti:
http://www.linuxlaboratory.org/27.php

__________________
When once you have tasted flight, you will walk the earth, forever more, with your eyes turned skyward. For there you have been, and there you long to return.

“Dovere, tempo, destino, tutto tende a separarci e, di fatto, ci separa. Ma il sentimento non conosce frontiere e mi unisce a te come se avessi sempre la mia mano sulla tua"

Last edited by Viry on 26-08-2005 at 17:31

26-08-2005 17:26
Click Here to See the Profile for Viry Click here to Send Viry a Private Message Find more posts by Viry Add Viry to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Viry
dsy moderator

User info:
Registered: Oct 2002
Posts: 2429 (0.29 al dì)
Location: Milano
Corso: Ticom
Anno: primo
Time Online: 43 Days, 3:27:12 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

In ogni caso, per controllare su una stringa e' uguale a un'altra, si usa if test:
in questo caso voglio che lo script dice gatto se lanciato con -e

code:
if test $1 = "-e"; then echo "gatto"; fi


viry@nocciolina ~ $ sh prova.sh -e
gatto
viry@nocciolina ~ $ sh prova.sh -i
viry@nocciolina ~ $

__________________
When once you have tasted flight, you will walk the earth, forever more, with your eyes turned skyward. For there you have been, and there you long to return.

“Dovere, tempo, destino, tutto tende a separarci e, di fatto, ci separa. Ma il sentimento non conosce frontiere e mi unisce a te come se avessi sempre la mia mano sulla tua"

26-08-2005 17:40
Click Here to See the Profile for Viry Click here to Send Viry a Private Message Find more posts by Viry Add Viry to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
lallyblue
.grande:maestro.

User info:
Registered: Sep 2002
Posts: 2868 (0.34 al dì)
Location: un puntino nello spazio infinito
Corso: Informatica
Anno: ZERO!
Time Online: 29 Days, 9:48:21 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by Viry
Senza diventare matti, c'e' getopts per fare cio':
Nell'esempio lo script accetta le opzioni -h -a -b -c
code:
while getopts "habc" opt; do case $opt in h ) visualizzo_help ;; a) eseguo_una_cosa;; b ) faccio_altra_cosa;; .... esac done

Molto piu' comodo, no?
Qui la man page:
http://www.ss64.com/bash/getopts.html
e un po' di esempietti:
http://www.linuxlaboratory.org/27.php


x curiosità: ma questo funziona anche quando ho opzioni tipo -ue, -uq ovvero con + lettere assieme? (sì so che -ue è come dire -u -e ma se l'utente inserisce -ue non va + bene x lo script, giusto? )

cmq lo tengo presente x la prossima occasione... x questa volta ho risolto con il case, effettivamente è quello che rende meglio :)

ora sto litigando un po' con il grep...
dal man mi sembra di aver capito che basta usare anche qui le regexp...
diciamo che ho un file "file.txt" che contiene una riga con "ciao pippo blah blah" e un'altra riga con "www.pippo.pip"
con il comando
cat file.txt | egrep \<pippo\>
mi aspetto di trovare solo la riga relativa a "ciao pippo blah blah" ovvero solo quella contornata da spazi, giusto?
ho provato anche \bpippo\b..
ma in entrambi i casi mi stampa entrambe le righe... ma se voglio la stringa esatta, contornata da spazi, che devo fa?!? :pensa:
tnxtnx!

__________________
*** Proposta di legge di iniziativa popolare: "8x1000 ALLA RICERCA"
Informati e firma la petizione! E' nel tuo interesse! ;)

*** Browse my dA gallery ! ;)
***In medio stat virtus

29-08-2005 18:53
Click Here to See the Profile for lallyblue Click Here to See the Blog of lallyblue Click here to Send lallyblue a Private Message Visit lallyblue's homepage! Find more posts by lallyblue Add lallyblue to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 22:38.    Post New Thread    Post A Reply
Pages (5): « 1 [2] 3 4 5 »   Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.057 seconds (77.12% PHP - 22.88% MySQL) con 23 query.