Reputation: 23
I like to run Python through the command line.
Sometimes, when I'm working with recursion or while loops, I'll want to look at output to help debug. Especially with infinite while loops gone awry, it can be fairly awful to navigate to the line in terminal where I called Python, if I need to scroll through thousands of lines above.
Is there a way to easily get to that line? I tried searching around, but as I'm fairly useless with Bash, I don't know how to better search for this question. Also, if anyone knows some good beginner resources for doing things besides changing directories, I'm interested in becoming more proficient.
Upvotes: 0
Views: 77
Reputation: 96
If you mean you want to find the command in your history to execute it again within bash, you could do one of the following:
If using emacs style editing (default) you can do a reverse search by pressing CTRL-r
and typing a few characters (such as python
). You can then press CTRL-r
to move backwards through previous commands containing python
.
If using vi style editing (set -o vi
) you can press ESC
then /
and type a few characters (such as python
) then press ENTER
. You can then press n
to move backwards through previous commands containing python
.
You can call history, piping through grep:
history|grep python
which will output your previous commands containing python:
541 python ./myscript.py
574 python ./myscript.py dostuff
Bash then allows you to execute that previous command with the !
prefix and the history number:
!541
Upvotes: 1