# NOTE -- I put a blank line between commands to try to increase
#     readability. I hope this doesn't imply that some commands
#     are outputting an additional blank line -- beware!

Last login: Tue Oct 30 15:01:46 on ttys008
Math-Tuttle-OSX:~ smtuttle$ cd humboldt/f12cs279/279lectures/279lect11-1
Math-Tuttle-OSX:279lect11-1 smtuttle$ history
    2  fg
    3  emacs 235lab10-projected.txt
    4  cp 235lab10-projected.txt play
... <chopped middle of long history file output> ...
  499  sftp st10@nrs-labs.humboldt.edu
  500  cd humboldt/f12cs279/279lectures/279lect11-1
  501  history

Math-Tuttle-OSX:279lect11-1 smtuttle$ !!
history
    4  cp 235lab10-projected.txt play
    5  cd play
... <chopped middle of long history file output> ...
  499  sftp st10@nrs-labs.humboldt.edu
  500  cd humboldt/f12cs279/279lectures/279lect11-1
  501  history
  502  history
  503  history

Math-Tuttle-OSX:279lect11-1 smtuttle$ more try-bang.sh 
#!/bin/bash

# question: does !! work in a shell script?

emacs test2.txt
!!

Math-Tuttle-OSX:279lect11-1 smtuttle$ try-bang.txt
-bash: try-bang.txt: command not found

Math-Tuttle-OSX:279lect11-1 smtuttle$ try-bang.sh
./try-bang.sh: line 6: !!: command not found

Math-Tuttle-OSX:279lect11-1 smtuttle$ history | tail
  498  cd 235lect11
  499  sftp st10@nrs-labs.humboldt.edu
  500  cd humboldt/f12cs279/279lectures/279lect11-1
  501  history
  502  history
  503  history
  504  more try-bang.sh 
  505  try-bang.txt
  506  try-bang.sh
  507  history | tail

Math-Tuttle-OSX:279lect11-1 smtuttle$ !499
sftp st10@nrs-labs.humboldt.edu
st10@nrs-labs.humboldt.edu's password: 

Math-Tuttle-OSX:279lect11-1 smtuttle$ !ssh
ssh st10@nrs-labs.humboldt.edu
st10@nrs-labs.humboldt.edu's password: 

Math-Tuttle-OSX:279lect11-1 smtuttle$ history | tail
  501  history
  502  history
  503  history
  504  more try-bang.sh 
  505  try-bang.txt
  506  try-bang.sh
  507  history | tail
  508  sftp st10@nrs-labs.humboldt.edu
  509  ssh st10@nrs-labs.humboldt.edu
  510  history | tail

Math-Tuttle-OSX:279lect11-1 smtuttle$ !?bang
try-bang.sh
./try-bang.sh: line 6: !!: command not found

Math-Tuttle-OSX:279lect11-1 smtuttle$ !hist
history | tail
  503  history
  504  more try-bang.sh 
  505  try-bang.txt
  506  try-bang.sh
  507  history | tail
  508  sftp st10@nrs-labs.humboldt.edu
  509  ssh st10@nrs-labs.humboldt.edu
  510  history | tail
  511  try-bang.sh
  512  history | tail

Math-Tuttle-OSX:279lect11-1 smtuttle$ !-2
try-bang.sh
./try-bang.sh: line 6: !!: command not found

(reverse-i-search)`more ': more try-bang.sh 

Math-Tuttle-OSX:279lect11-1 smtuttle$ ls
#279lect11-1-projected.txt#
279lect11-1-projected.txt
279lect11-1-projected.txt~
279lect11-1.odt
279lect11-1.pdf
barbq.txt
foodiebar.txt
looky.txt
looky.txt~
stuff.txt
test1.txt
test10.txt
test11.txt
test12.txt
test13.txt
test14.txt
test15.txt
test2.txt
test22.txt
test3.txt
test4.txt
test5.txt
test6.txt
test7.txt
test8.txt
test9.txt
try-bang.sh

Math-Tuttle-OSX:279lect11-1 smtuttle$ emacs test2.txt
Math-Tuttle-OSX:279lect11-1 smtuttle$ ^2^7^
emacs test7.txt

Math-Tuttle-OSX:279lect11-1 smtuttle$ ^7^22^
emacs test22.txt

Math-Tuttle-OSX:279lect11-1 smtuttle$ ^2^4^
emacs test42.txt

Math-Tuttle-OSX:279lect11-1 smtuttle$ emacs test22.txt
Math-Tuttle-OSX:279lect11-1 smtuttle$ ^2^4^g
emacs test42.txtg

Math-Tuttle-OSX:279lect11-1 smtuttle$ !?test22
emacs test22.txt

Math-Tuttle-OSX:279lect11-1 smtuttle$ !!:gs/2/4/
emacs test44.txt

Math-Tuttle-OSX:279lect11-1 smtuttle$ !-2:gs/2/4
emacs test44.txt

Math-Tuttle-OSX:279lect11-1 smtuttle$ !hist
history | tail
  515  emacs test2.txt
  516  emacs test7.txt
  517  emacs test22.txt
  518  emacs test42.txt
  519  emacs test22.txt
  520  emacs test42.txtg
  521  emacs test22.txt
  522  emacs test44.txt
  523  emacs test44.txt
  524  history | tail

Math-Tuttle-OSX:279lect11-1 smtuttle$ !516:gs/t/x/
emacs xesx7.xxx

Math-Tuttle-OSX:279lect11-1 smtuttle$ ls
#279lect11-1-projected.txt#
279lect11-1-projected.txt
279lect11-1-projected.txt~
279lect11-1.odt
279lect11-1.pdf
barbq.txt
foodiebar.txt
looky.txt
looky.txt~
stuff.txt
test1.txt
test10.txt
test11.txt
test12.txt
test13.txt
test14.txt
test15.txt
test2.txt
test22.txt
test3.txt
test4.txt
test5.txt
test6.txt
test7.txt
test8.txt
test9.txt
try-bang.sh

Math-Tuttle-OSX:279lect11-1 smtuttle$ ls foo*
foodiebar.txt

Math-Tuttle-OSX:279lect11-1 smtuttle$ more foodiebar.txt 
foo foo foo
foo foo foo
foo die bar bar bar
bar bar bar
foo foo foo
foo die bar die foo

Math-Tuttle-OSX:279lect11-1 smtuttle$ sed -e 's/foo/bar/' foodiebar.txt > barbq.txt

Math-Tuttle-OSX:279lect11-1 smtuttle$ more barbq.txt 
bar foo foo
bar foo foo
bar die bar bar bar
bar bar bar
bar foo foo
bar die bar die foo

Math-Tuttle-OSX:279lect11-1 smtuttle$ sed -e 's/foo/bar/g' foodiebar.txt > barbq2.txt

Math-Tuttle-OSX:279lect11-1 smtuttle$ more barbq2.txt 
bar bar bar
bar bar bar
bar die bar bar bar
bar bar bar
bar bar bar
bar die bar die bar

Math-Tuttle-OSX:279lect11-1 smtuttle$ ls *.sh
try-bang.sh

Math-Tuttle-OSX:279lect11-1 smtuttle$ emacs try-bang.sh

[1]+  Stopped                 emacs try-bang.sh

Math-Tuttle-OSX:279lect11-1 smtuttle$ fg
emacs try-bang.sh

Math-Tuttle-OSX:279lect11-1 smtuttle$ fg
-bash: fg: current: no such job

Math-Tuttle-OSX:279lect11-1 smtuttle$ sed -e 's/#.*//;s/^$//' try-bang.sh




echo "howdy"    
emacs test2.txt
!!

Math-Tuttle-OSX:279lect11-1 smtuttle$ sed -e '/^$/d' try-bang.sh
#!/bin/bash
# question: does !! work in a shell script?
echo "howdy"    # this is an in-line-comment
emacs test2.txt
!!

Math-Tuttle-OSX:279lect11-1 smtuttle$ sed -e 's/#.*//;/^$/d' try-bang.sh
echo "howdy"    
emacs test2.txt
!!

Math-Tuttle-OSX:279lect11-1 smtuttle$ sed -e '/^$/d;s/#.*//' try-bang.sh


echo "howdy"    
emacs test2.txt
!!

Math-Tuttle-OSX:279lect11-1 smtuttle$ more foodiebar.txt 
foo foo foo
foo foo foo
foo die bar bar bar
bar bar bar
foo foo foo
foo die bar die foo

Math-Tuttle-OSX:279lect11-1 smtuttle$ sed -e '/bar/d' foodiebar.txt 
foo foo foo
foo foo foo
foo foo foo

Math-Tuttle-OSX:279lect11-1 smtuttle$ sed -e '3d' foodiebar.txt 
foo foo foo
foo foo foo
bar bar bar
foo foo foo
foo die bar die foo

Math-Tuttle-OSX:279lect11-1 smtuttle$ cat foodiebar.txt 
foo foo foo
foo foo foo
foo die bar bar bar
bar bar bar
foo foo foo
foo die bar die foo

Math-Tuttle-OSX:279lect11-1 smtuttle$ sed -e '/foo/,/bar/d' foodiebar.txt 
bar bar bar

Math-Tuttle-OSX:279lect11-1 smtuttle$ sed -e '2,4d' foodiebar.txt 
foo foo foo
foo foo foo
foo die bar die foo

Math-Tuttle-OSX:279lect11-1 smtuttle$ sed -e '2,$d' foodiebar.txt 
foo foo foo

Math-Tuttle-OSX:279lect11-1 smtuttle$