5

I'd like to be able to run a spark-shell command via it's history number. When I type :history or :h?, I then cut and paste the command - even though the history command gives it an ID number. I'd like to be able to type

:61

or something to just rerun the command. Is there something like that?

Justin Pihony
  • 66,056
  • 18
  • 147
  • 180
dommer
  • 19,610
  • 14
  • 75
  • 137

4 Answers4

9

You can press control + R, then start typing to search for your command. You can then press enter to run, or you can edit the command before running, like in readline.

dpeacock
  • 2,697
  • 13
  • 16
7

Yes It is possible to use the use HISTORY command in spark shell

scala> :history

or

scala> :22

or

scala> ctrl + r

Viraj Wadate
  • 5,447
  • 1
  • 31
  • 29
3

dpeacock's answer is probably the best you can get currently.

If you look at this SO question you can see that you could load the history yourself, but loading and running it is another story as I cannot seem to find a way to get access to the ILoop variable, which is the interactive loop that you could run an interpret command through.

To load the history, just do

val history = new FileHistory(new File("HOME/.spark_history"))
history.index //gives you the current number
history.moveTo(NUMBER) //moves the cursor
history.current //gives you the command you want

You could wrap this all up in an object, but without the ILoop you would still need to copy and paste. So....the short answer is not really

Justin Pihony
  • 66,056
  • 18
  • 147
  • 180
2

In Linux it will be present in /home/<userid>/scala_history for spark-shell

jizhihaoSAMA
  • 12,336
  • 9
  • 27
  • 49
Harish Masand
  • 319
  • 2
  • 3