|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
The output of a script is somethinh like:
$./foo.sh 123 123 123 123 123 123 123 123 123 I have to rename the directory when I run that script if all the values in output are the same, but.. how can I compare all that values? (I don't know how much values I will get). Tanks a lot. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
2007-09-09, 23:02(+02), slystoner:
> The output of a script is somethinh like: > > $./foo.sh > 123 > 123 > 123 > 123 > 123 > 123 > 123 > 123 > 123 > > > I have to rename the directory when I run that script if all the values > in output are the same, but.. how can I compare all that values? (I > don't know how much values I will get). [...] if ./foo.sh | awk 'NR > 1 && $0 != last {exit 1} {last = $0}' then echo "all the lines output by ./foo.sh were identical" else echo "they were not" fi -- Stéphane |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
"slystoner" wrote ... > The output of a script is somethinh like: > > $./foo.sh > 123 > 123 > 123 > 123 > 123 > 123 > 123 > 123 > 123 > > > I have to rename the directory when I run that script if all the values in > output are the same [...] With zsh: [[ $(print ${(u)$(foo.sh)}) = 123 ]]&&mv ... Dimitre |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
2007-09-9, 23:33(+02), Radoulov, Dimitre:
[...] > With zsh: > > [[ $(print ${(u)$(foo.sh)}) = 123 ]]&&mv ... [...] Except that if the output contains empty lines (and if that's a problem), they will not be noticed. And note that print '\006123' also outputs "123" (followed by a LF). -- Stéphane |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
"Stephane CHAZELAS" wrote ... > 2007-09-9, 23:33(+02), Radoulov, Dimitre: > [...] >> With zsh: >> >> [[ $(print ${(u)$(foo.sh)}) = 123 ]]&&mv ... > [...] > > Except that if the output contains empty lines (and if that's a > problem), they will not be noticed. And note that print > '\006123' also outputs "123" (followed by a LF). Thanks for pointing that. So if the value is unknown and the above mentioned is not a problem: [ ${#${(u)$(foo.sh)}} -eq 1 ]&&mv ... Dimitre |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Stephane CHAZELAS ha scritto:
> if ./foo.sh | > awk 'NR > 1 && $0 != last {exit 1} {last = $0}' > then > echo "all the lines output by ./foo.sh were identical" > else > echo "they were not" > fi > I found a solution but.. your's so compact! Damn.. Stephane rocks! ![]() function checkDIR() { FOO=`./script,sh' | tail -1` for ITEM in `./script.sh`; do if [$FOO -eq $ITEM] then return 0 fi done return 1 } if checkDIR; do .... |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
Stephane CHAZELAS wrote: > 2007-09-09, 23:02(+02), slystoner: > > The output of a script is somethinh like: > > > > $./foo.sh > > 123 > > 123 > > 123 > > 123 > > 123 > > 123 > > 123 > > 123 > > 123 > > > > > > I have to rename the directory when I run that script if all the values > > in output are the same, but.. how can I compare all that values? (I > > don't know how much values I will get). > [...] > > if ./foo.sh | > awk 'NR > 1 && $0 != last {exit 1} {last = $0}' > then > echo "all the lines output by ./foo.sh were identical" > else > echo "they were not" > fi ruby -e 'exit 1 if ARGF.to_a.uniq.size>1' |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
On Sep 10, 7:06 am, William James <w_a_x_...@yahoo.com> wrote:
> Stephane CHAZELAS wrote: > > 2007-09-09, 23:02(+02), slystoner: > > > The output of a script is somethinh like: > > > > $./foo.sh > > > 123 > > > 123 > > > 123 > > > 123 > > > 123 > > > 123 > > > 123 > > > 123 > > > 123 > > > > I have to rename the directory when I run that script if all the values > > > in output are the same, but.. how can I compare all that values? (I > > > don't know how much values I will get). > > [...] > > > if ./foo.sh | > > awk 'NR > 1 && $0 != last {exit 1} {last = $0}' > > then > > echo "all the lines output by ./foo.sh were identical" > > else > > echo "they were not" > > fi > > ruby -e 'exit 1 if ARGF.to_a.uniq.size>1' ![]() |
|
![]() |
| Outils de la discussion | |
|
|