I'm using bash to execute complex scripts having for and wile loops. I activate the history in the script using :
set -o history -o histexpand
But if I execute the following script:
#!/bin/bash
set -o history -o histexpand
for i in 1 2 3 4 5
do
echo "Welcome $i times"
done
history
I can see that 'history' does not track commands inside the for loop :
[scripts]$ ~/test2.sh
Welcome 1 times
Welcome 2 times
Welcome 3 times
Welcome 4 times
Welcome 5 times
1 for i in 1 2 3 4 5; do echo "Welcome $i times"; done
2 history
Is there a way to track the commands inside the for loop also ? In this present sample, I would love to get the following result :
[scripts]$ ~/test2.sh
Welcome 1 times
Welcome 2 times
Welcome 3 times
Welcome 4 times
Welcome 5 times
1 for i in 1 2 3 4 5; do echo "Welcome $i times"; done
2 echo "Welcome $i times"
3 echo "Welcome $i times"
4 echo "Welcome $i times"
5 echo "Welcome $i times"
6 echo "Welcome $i times"
7 history