J ai encore une petit soucis, cette fois-ci dans une boucle for.

Donnees:
- le fichier texte 'allstat_overlap.txt'allstat_overlap.txt
- le code suivant
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
 
#!/bin/bash
# Specify pat and seg
 
# test
#
# Return the atlas number for which the highest overlap is computed
#
 
 
# Inputs
fimgs="`seq 0 7`"
strs="Ao"
 
 
# Functions
function getAtlasNb()
{	
	argexitcode=65
	pat="undefined"
	seg="undefined"
	while getopts "p:s:" argje
	do
	  case $argje in
		p) pat="$OPTARG";;
		s) seg="$OPTARG";;
		*) echo "ERROR: Wrong arguments!"; exit $argexiterror;;
	  esac
	done
 
	if [ "$pat" = "undefined" ]
	then
	  echo "ERROR_pat: Not enough arguments!"; exit $argexitcode  
	fi
	if [ "$seg" = "undefined" ]
	then
	  echo "ERROR_seg: Not enough arguments!"; exit $argexitcode  
	fi
 
	file='allstat_overlap.txt'
 
	cpt=1;
	# cpt=1 : transform
	# cpt=2 : overlap
	# cpt=2p+1: pxxxpyyy
	# cpt=2p: 0.abcdef
	header=2;
 
	start=$(($header+$pat*7*2))
	overlap=0;
 
	# Read each expression in each line
	for line in $(cat $file); 
		do 
		# Only look at the part we are interested in
		if [ $cpt -gt $start ] && [ $cpt -lt $(($start+2*8-1)) ]
			then
			if [ $(expr $cpt % 2) -eq 1 ]
				then
				temp=$line;
				comb=${temp:$((${#temp}-1)):1};
			fi
 
			if [ $(expr $cpt % 2) -eq 0 ]
				then
				#echo 
				ov=$line
				# Test to find the atlas which gives the highest overlap
				if [ $(expr $ov \> $overlap) -eq 1 ]
					then
					overlap=$ov;
					atlas=$comb;
				fi
			fi
		fi
		cpt=$(($cpt + 1))
	done
	return $atlas
	exit 0;
}
 
 
# Processing
for fimg in $fimgs
	do
	echo fimg $fimg
	for str in $strs
		do
		echo -e "\tseg: "$str
		getAtlasNb -p $fimg -s $str
		echo -e "\tatlas selection:" $? "\n"		# $? : value returned by getAtlasMb fonction
	done
done
Mon probleme se situe dans la boucle for de la partie #Processing.
A la premiere iteration, pas de probleme, la fonction getAtlasNb lit bien les parametres d entree, et me renvoie une valeur correcte. Mais des la seconde iteration, j ai l erreur suivante:
ERROR_pat: Not enough arguments!
ce qui signifie que l argument d entree de la fonction getAtlasNb n est pas pris en compte.
Et je ne comprends malheureusement pas pourquoi...

Merci de votre aide.