Shell Testing shell scripts

For many years whenever I wanted to test the reseults of a sed, find etc command I wrote a one or two line shell script and ran it to see the results, this ending up with an accumulated mess of hundreds of undocumented scripts.

After several months trying to figure out how emacs org babel tangle works I now use something like this construct:

Code:
* display only lines without comments or having blank lines                                                                                                                                                                   

  #+begin_src sh

  sed -E '/^[[:space:]]*($|#)/d' /tmp/dnsmasq.conf > /tmp/dnsmasq.tmp                                                                                                                                                                
  #+end_src
                                                                                                                                                                                                                                                    
  #+RESULTS:                                                                                                                                                                                                                                                    

* some find commands
                                                                                                                                                                                                                                   
  #+begin_src sh
                                                                                                                                                                                                                                             
  find /tmp -type d -name 'mc*' -empty -delete
                                                                                                                                                                                               
  #+end_src
                                                                                                                                                                                                                                                    
  #+RESULTS:

Ctr-c activates the #+begin #+end block. The output is shown under #+RESULTS

this is an *.org file and you need to activete Babel languages in your emacs configuration for this to work.

It took me ages to figure this out, but I'm glad I did.
 
Hi Mate

you can improve your org file by naming the source code blocks
and naming your results blocks as well

this allows you to move the results blocks under a results header

that way you can separate the code from the results
which is much cleaner

Code:
#+STARTUP: content
* code
** display only lines without comments or having blank lines

#+NAME: sed-comments
#+begin_src sh
sed -E '/^[[:space:]]*($|#)/d' /tmp/dnsmasq.conf > /tmp/dnsmasq.tmp
#+end_src

** some find commands

#+NAME: find-commands
#+begin_src sh
find /tmp -type d -name 'mc*' -empty -delete
#+end_src

** results
*** sed

#+RESULTS: sed-comments

*** find

#+RESULTS: find-commands

i would also reccomend looking at noweb
for literate programming



You can also tangle files to multiple locations as well

emacs config


dotfiles


dotfiles org file


dotfiles org file raw


Here are my emacs notes


root dotfiles


root dotfiles org file


root dotfiles org file raw


changelog to keep track of git repos


changelog to keep track of git repos raw


Heres how i tangle my root config files


emacs playlist

 
Many thanks for your suggestions.

I will be studying them attentively.

I'm still very much a novice with emacs. I wish I had started with it 10 years ago, and have only recently made some progress with babel which took a long time to get the hang of.
 
you can do very cool things with org babel

like having one code block call another code block
and pass a variable to a function in the second code block
emacs has a very steep learning cliff. I tried giving it a try periodically over a number of years but always gave up in frustration. Eventually stumbled upon Doom which simplified things greatly although I still have a great deal to learn.

org babel seems to be hidden away and it is difficult to come across examples of it's usage if you don't know about it.

I look forward to doing some 'cool things'.

Do you have an example of passing variables between blocks?
 
Back
Top