|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Nov 2010
Messaggi: 71
|
[script bash] confronto tra due numeri
Ciao a tutti. Sto iniziando da poco ad usare gli script bash da ubuntu e mi sto trovando in difficoltà. Il mio script deve semplicemente(per più esperti di me) scrivere in output il risultato del confronto tra due numeri (maggiore o minore).
Codice:
#!/bin/sh
echo "valore primo e $1"
echo "valore secondo e $2"
if [test $1 -lt $2]; then
echo " $1 minore $2 "
else
echo " $2 maggiore $1 "
fi
./script.sh 4 5 in output mi da l errore : test not found però mi da correttamente 5 ($2) maggiore di 4($1). qualcuno saprebbe aiutarmi ???? grazie in anticipo. |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
|
Codice:
#!/bin/sh
echo "valore primo e $1"
echo "valore secondo e $2"
if [ $1 -lt $2]; then
echo " $1 minore $2 "
else
echo " $2 maggiore $1 "
fi
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele |
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
|
Oppure anche
Codice:
#!/bin/sh
echo "valore primo e $1"
echo "valore secondo e $2"
if $( test $1 -lt $2); then
echo " $1 minore $2 "
else
echo " $2 maggiore $1 "
fi
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele |
|
|
|
|
|
#4 | |
|
Member
Iscritto dal: Nov 2010
Messaggi: 71
|
Quote:
l output me lo da giusto come hai fatto tu però prima mi dice : ./confronto.sh: 8: [4: not found 4 maggiore 1 |
|
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
|
Hai lasciato lo spazio tra la [ e il $1?
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele |
|
|
|
|
|
#6 | |
|
Senior Member
Iscritto dal: Mar 2001
Città: PV Milano Nord
Messaggi: 3851
|
Quote:
ma $1 minore $2 = $2 maggiore $1
__________________
"W la foca, che dio la benedoca"
poteva risolvere tutto la sinistra negli anni in cui ha governato e non l'ha fatto. O sono incapaci o sta bene anche a "loro" cosi. L'una o l'altra inutile scandalizzarsi.[plutus] |
|
|
|
|
|
|
#7 |
|
Member
Iscritto dal: Nov 2010
Messaggi: 71
|
si bisognava lasciare lo spazio anke tra $2 e ].
Codice:
#!/bin/sh
echo "valore primo e $1"
echo "valore secondo e $2"
if [ $1 -lt $2 ]; then
echo "$1 minore $2 "
else
echo "$1 maggiore $2 "
fi
Se invece voglio usare la variabile test devo farlo in questo modo: Codice:
#!/bin/sh
echo "valore primo e $1"
echo "valore secondo e $2"
if test $1 -lt $2 ; then
echo "$1 minore $2 "
else
echo "$1 maggiore $2 "
fi
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 00:02.




















