foo: calcola la cifra massima della stringa $1, la pone in $a, pone in $b il resto della stringa stessa.
bar: usa foo per ordinare le cifre di $1.
Il risultato puo' essere calcolato eseguendo lo script:
#!/bin/bash
function foo (){
local i=0
local j=-1
while (( $i<${#1} )) ; do \
if test ${1:$i:1} -gt $j ; \
then j=${1:$i:1} ; \
fi ; \
i=$i+1 ; \
done
i=0
while (( $i<${#1} )) ; do \
if test ${1:$i:1} -eq $j ; \
then b=${1:0:$i}${1:$i+1} ; \
break ; \
fi ; \
i=$i+1 ; \
done
a=$j
}
a=0
d=""
b=0
function bar(){
local i=0
local c=$1
while (( ${#c} )) ; do \
foo $c ; \
c=$b ; \
d=$d$a ; \
done
}
bar $1
echo $d
Input di rpcgen:
struct input_data {
string text<1024>;
string delim<16>;
}
struct output_data {
int nwords;
float avg_len;
}
typedef struct input_data input_data;
typedef struct output_data output_data;
typedef string help_data[SIZE_OF_HELP];
program WCPROG {
version WCVERSION1 {
output_data wcount(input_data) = 1;
helpdata help(void) = 2;
} = 1;
} = 44444;
L'implementazione consiste nell'impiegare strtok per estrarre le parole una alla volta, e calcolarne la lunghezza:
char *curr=strtok(text,delim);
int wc=0;
int tot_len=0;
while(curr) {
wc++;
tot_len+=strlen(curr);
curr=strtok(NULL,delim);
}
Il valore di ritorno va inserito in una struttura analoga a quella dichiarata in XDR.
ip link set wlan0 up (oppure ifconfig wlan0 up).chmod a-s, da root.