Skip to main content
2 of 5
Modify title to better reflect question
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

Bash for loop - can the commands in the loop be added to the shell's history?

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?

Lavya
  • 1.7k
  • 5
  • 23
  • 28