CSC231 Bash Tutorial 2

From dftwiki3
Revision as of 09:14, 9 February 2017 by Thiebaut (talk | contribs) (Even fewer keystrokes with !)
Jump to: navigation, search

--D. Thiebaut (talk) 09:06, 9 February 2017 (EST)


Your History


The Bash shell keeps track of all the commands you type, at least the most recent ones. This list of commands is kept in a file, and when you login to your Linux account, the commands that you typed the last time you were connected are still in this file, available to you.

Let's figure out how to use your history to reduce your typing.

  • If you do not have a working hello.asm program, get a copy of my version:
getcopy hello.asm

  • Assemble, link, and run your program
nasm -f elf hello.asm
ld -melf_i386 hello.o -o hello
./hello

  • You should see the message printed.


Up and Down your History


  • Edit hello.asm and modify the message, so that the program will print something different. It doesn't matter what.
emacs hello.asm

  • You now have to assemble, link, and run your program again to see the result of the modification. Instead of typing the commands again...
  • just press the UP arrow key on your keyboard a few times until your last nasm command. Press Enter when you have the command at the prompt.
  • then press UP arrow again a few times and get the last ld command. Enter
  • then press UP arrow again, and get ./hello


You get the idea!



Fewer Keystrokes with !


  • Go ahead and make another edit to change the message of your hello.asm program.
  • Instead of using the arrow keys, you can be even more succinct: You know that the command you want to execute, nasm, again starts with na, so, at the prompt, type
 !na

this will ask Bash to locate the most recent command starting with the characters 'n' 'a', and to run it. Try it!
  • Then try
!ld

  • and you now have assembled and linked your program another time.
  • You should have figured out a way to run it again:
!./

You do not need to use the first two characters. You could use just one. But if you do so, you may get the wrong command. For example, ls and ld start with the same letter "ell" so you would use two characters to specify that you want to repeat ld and not ls.