problem in shell script

hi every body
this is my first thread in this forum, i hope find a solution for my problem
i have to write a script bt i still have some error and i don't know how to correct them

[mayoura@mayoura final]$ for i in `seq 500 505`; do  ./generateur_tache  $i tache$i.txt; nprocs=$i; copt$i=`cat tache$i.txt | ./copt.awk` ;  ./generateur_machine $(( $i * 5 / 100 )) $copt$i machine  perf ; clpt$i=`./lpt $i $(( $i * 5 / 100 ))` ; ./gensched -t tache$i.txt -m machine$i -p perf$i -b 0 -g D -h D -o progdyn$i ;  cmax$i=`cat progdyn$i | ./cmax.awk`; echo ` $clpt$i - $copt$i`" "` $cmax$i - $copt$i`  ; done
bash: copt500=74.778: commande inconnue...
bash: clpt500=la: commande inconnue...
Invalid performance file
cat: progdyn500: Aucun fichier ou dossier de ce type
bash: cmax500=0: commande inconnue...

did any one have a solution please :confused:
thank u

Usually when I have some issues not understanding why my great one liner didn't work, I put it in a script - one process per line, so I can add echoes or use set -x...

What do you expect the following scripts to do ./generateur_tache ./copt.awk /generateur_machine ./gensched ./cmax.awk
Also could you format your script in a readable fashion (ie rewrite as a script rather than a command line hack.

Hi! And welcome to the forum...

First thing about your code, try to make it more readable, at least when posting here and also, try to "translate" the error messages to english, with error messages in other languages, only people that knows your language will be able to help you! =o)

I think the problem with your script, check the comment I put on it, below:

for i in `seq 500 505`
do
	./generateur_tache ${i} tache${i}.txt
	nprocs=${i}
	
	copt${i}=`cat tache$i.txt | ./copt.awk` # What you are trying to do here? Is it a typo? A variable name with a variable? it is not possible, as I know it... And why you need it?
	
	./generateur_machine $(( ${i} * 5 / 100 )) ${copt}${i} machine perf
	clpt$i=`./lpt $i $(( $i * 5 / 100 ))`
	./gensched -t tache${i}.txt -m machine${i} -p perf${i} -b 0 -g D -h D -o progdyn${i}
	cmax${i}=`cat progdyn${i} | ./cmax.awk`
	echo `${clpt}${i} - ${copt}${i}`" "` ${cmax}${i} - ${copt}${i}`
done

thank you for replying
so for the first code it will generate a file in wich i line
copt is a variable calculated from this file (the sum of the line divided by an other variable) this copt will be used in generateur-machine
in bref it's a scheduling problem to resolve , copt is the optimal makespan if u know about it
sorry for my poor english
and thank u again :slight_smile:

Hi, have you checked the comments I added in your code:

copt${i}=`cat tache$i.txt | ./copt.awk` # What you are trying to do here? Is it a typo? A variable name with a variable? it is not possible, as I know it... And why you need it?

yes i have all reay checked it and i answered , in fact i need this variable to use it in next command
as i have said the first code will generate a file with $i line (supposed as tasks to schedule each id of task with it's duration inside) the second file will take the variable copt (which is the optimal completition time calculated in copt.awk) and will generate a file containing the machines to do this tasks the number of machine is calculated from 5% of $i and the indisponibility are calculated from copt , then two scheduling algorithm will be tested , the first one in lpt(longest processing time) the completition time will be extracted from the terminal which is clpt and the second one from gensched which is a dynamic programming from which will be extracted cmax and then will be shown on the terminal the difference between copt, cmax and clpt

Ok... I can tell you that wherever you have a variable name defined by another variable value (eg

copt${i}=`cat tache$i.txt | ./copt.awk`

), the script will fail because this does not work on shell scripts.

Maybe you can replace it by an array, then you will be able to get the value back.

By the errors reported, what I commented above, caused them:

bash: copt500=74.778: commande inconnue...
bash: clpt500=la: commande inconnue...
...

I hope it helps...

a friend recommended me to do with arrays but i'm not really pro in shell programming so i don't really know how to proceed :cry:

Nothing special:

unset testArray
testArray[0]="foo"
testArray[1]="bar"
testArray[2]="foobar"

arrayCountPos=0
arrayLastPos=${#testArray[@]}

while [ ${arrayCountPos} -lt ${arrayLastPos} ]
do
     echo "Array pos[${arrayCountPos}] - Value: [${testArray[${arrayCountPos}]}]"
     arrayCountPos=`${arrayCountPos} + 1`
done

This is the way I am used to do, but there are always more than one way to do it. =o)

I hope it helps.

thank you, i will try it :slight_smile: