On the bash terminal if I execute the following for loop:
for i in {1..5}; do echo $i; done
The `echo` commands are not added to the history of the current shell. Is it because the commands in for (in `do` section) are run in subshell? If so is there a way to run them in the current shell instead? Or is it not possible because it's "running" `for` at the time?
Edit: Given it takes the entire for loop as one single compound command, if I remove the for loop and write the individual commands in five lines shouldn't all five be added to history?
I did the following:
#!/bin/bash
set -o history
var=5
echo $((var--))
echo $((var--))
echo $((var--))
echo $((var--))
echo $((var--))
and ran the script using `source`. Still in history it shows only one echo statement ` echo $((var--))
` and not all five. On the other hand, if instead of five ` echo $((var--))
` I put five `echo 5`, `echo 4`, ... `echo 1` commands all five are added to history.
Why?