I just can not get it right.
Script takes two arguments, target and command. Valid targets are specified within an array. If target is 'all', script should iterate through all targets.
#!/bin/bash
# recur.sh
targets=('aaa' 'bbb' 'ccc' 'ddd')
if [ "$1" == "all" ] ; then
for i in $targets ; do
echo $2" --> "$i
./$0 $i $2
done
exit 0
fi
echo "Target "$1" just received command '"$2"'"
exit 0
I expect the following output:
$ recur all boggle
boggle --> aaa
Target aaa just received command 'boggle'
boggle --> bbb
Target bbb just received command 'boggle'
boggle --> ccc
Target ccc just received command 'boggle'
boggle --> ddd
Target ddd just received command 'boggle'
But the script exits at the first iteration:
$ recur all boggle
boggle --> aaa
Target aaa just received command 'boggle'
echo
ing the different "targets"? What is the output you're getting now? – Joseph R. Jul 3 at 14:48echo "Target "$1" just received command '"$2"'"
part is complex. – Nyitrai Lőrinc Jul 3 at 14:51