Most viewed recipes tagged "bash"http://code.activestate.com/recipes/tags/bash/views/2017-01-08T17:48:57-08:00ActiveState Code RecipesBash script to create a header for Bash scripts (Bash)
2011-11-02T01:57:07-07:00userendhttp://code.activestate.com/recipes/users/4179007/http://code.activestate.com/recipes/577862-bash-script-to-create-a-header-for-bash-scripts/
<p style="color: grey">
Bash
recipe 577862
by <a href="/recipes/users/4179007/">userend</a>
(<a href="/recipes/tags/auto/">auto</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/create/">create</a>, <a href="/recipes/tags/emacs/">emacs</a>, <a href="/recipes/tags/gpl/">gpl</a>, <a href="/recipes/tags/header/">header</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/vim/">vim</a>).
Revision 3.
</p>
<p>This will create a header for a Bash script. It is a nice way keep a track of what your script does and when it was created, the author of the script, etc.. </p>
<p>It will open the script automatically with one of the two most popular editor out there, Vim or Emacs! It also checks to see if there is a script with the same name in the current working directory so it will not overwrite another file.</p>
<p>v0.4: I had to kick this up a notch. I took the suggestion of "dev h" to add a chance for the user to select another name for the script.</p>
<p>Please leave comments and suggestions.</p>
A UNIX-like "which" command for Python (Python)
2015-03-20T19:23:45-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579035-a-unix-like-which-command-for-python/
<p style="color: grey">
Python
recipe 579035
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/commands/">commands</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/which/">which</a>).
</p>
<p>UNIX users are familiar with the which command. Given an argument called name, it checks the system PATH environment variable, to see whether that name exists (as a file) in any of the directories specified in the PATH. (The directories in the PATH are colon-separated on UNIX and semicolon-separated on Windows.)</p>
<p>This recipe shows how to write a minimal which command in Python.
It has been tested on Windows.</p>
Line-oriented processing in Python from command line (like AWK) (Python)
2011-04-14T19:49:16-07:00Artur Siekielskihttp://code.activestate.com/recipes/users/4177664/http://code.activestate.com/recipes/577656-line-oriented-processing-in-python-from-command-li/
<p style="color: grey">
Python
recipe 577656
by <a href="/recipes/users/4177664/">Artur Siekielski</a>
(<a href="/recipes/tags/awk/">awk</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/shell/">shell</a>).
</p>
<p>A very simple but powerful shell script which enables writing ad-hoc Python scripts for processing line-oriented input. It executes the following code template:</p>
<pre class="prettyprint"><code>$INIT
for line in sys.stdin:
$LOOP
$END
</code></pre>
<p>where $INIT, $LOOP and $END code blocks are given from command line. If only one argument is given, then $INIT and $END are empty. If two arguments are given, $END is empty.</p>
<p>Examples (script is saved as 'pyk' in the $PATH):</p>
<ul>
<li>"wc -l" replacement:
$ cat file | pyk 'c=0' 'c+=1' 'print c'</li>
<li>grep replacement:
$ cat file | pyk 'import re' 'if re.search("\d+", line): print line'</li>
<li>adding all numbers:
$ seq 1 10 | pyk 's=0' 's+=int(line)' 'print s'</li>
<li>prepending lines with it's length:
$ cat file | pyk 'print len(line), line'</li>
<li>longest file name:
$ ls -1 | pyk 'longest=""' 'if len(line) > len(longest): longest=line' 'print longest'</li>
<li>number of unique words in a document:
$ pyk 'words=[]' 'words.extend(line.split())' 'print "All words: {}, unique: {}".format(len(words), len(set(words))'</li>
</ul>
Collection Pipeline in Python (Python)
2016-03-16T14:45:02-07:00Steven D'Apranohttp://code.activestate.com/recipes/users/4172944/http://code.activestate.com/recipes/580625-collection-pipeline-in-python/
<p style="color: grey">
Python
recipe 580625
by <a href="/recipes/users/4172944/">Steven D'Aprano</a>
(<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/filter/">filter</a>, <a href="/recipes/tags/map/">map</a>, <a href="/recipes/tags/pipe/">pipe</a>, <a href="/recipes/tags/pipline/">pipline</a>).
</p>
<p>A powerful functional programming technique is the use of pipelines of functions. If you have used shell scripting languages like <code>bash</code>, you will have used this technique. For instance, to count the number of files or directories, you might say: <code>ls | wc -l</code>. The output of the first command is piped into the input of the second, and the result returned.</p>
<p>We can set up a similar pipeline using Lisp-like Map, Filter and Reduce special functions. Unlike the standard Python <code>map</code>, <code>filter</code> and <code>reduce</code>, these are designed to operate in a pipeline, using the same <code>|</code> syntax used by bash and other shell scripting languages:</p>
<pre class="prettyprint"><code>>>> data = range(1000)
>>> data | Filter(lambda n: 20 < n < 30) | Map(float) | List
[21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0]
</code></pre>
<p>The standard Python functional tools is much less attractive, as you have to write the functions in the opposite order to how they are applied to the data. This makes it harder to follow the logic of the expression.</p>
<pre class="prettyprint"><code>>>> list(map(float, filter(lambda n: 20 < n < 30, data)))
[21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0]
</code></pre>
<p>We can also end the pipeline with a call to <code>Reduce</code> to collate the sequence into a single value. Here we take a string, extract all the digits, convert to ints, and multiply:</p>
<pre class="prettyprint"><code>>>> from operator import mul
>>> "abcd12345xyz" | Filter(str.isdigit) | Map(int) | Reduce(mul)
120
</code></pre>
Obfuscation In Bash Shell. (Bash)
2014-12-19T20:01:30-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578986-obfuscation-in-bash-shell/
<p style="color: grey">
Bash
recipe 578986
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/obfuscation/">obfuscation</a>).
</p>
<p>IMO, the immense power of the shell...</p>
<p>Please let me know if there is any other human readable language that can do this...</p>
<p>The DEMO code below was an idea I formed to see how to make a bash script very difficult to hack.</p>
<p>Everything in it is made easy to read so as to see this idea working.</p>
<p>It uses bash variables ONLY and although I have used bash loops to create the variables in this
DEMO you could create your own set of variables and 'source' them to the the obfuscated code before
running the main body of the code.</p>
<p>It also goes without saying that you could obfuscate the changing of any or all the variable
allocations at any time AFTER the code runs to make it even more obfuscated and as may times as
you wish...</p>
<p>I would be seriously difficult to actually write a lsrge bash app' using this method but boy oh boy
would it be fun?!?</p>
<p>Testbed:- Macbook Pro, OSX 10.7.x and above, using default bash terminal...</p>
<p>LBNL, yeah I am aware of 'eval' but as it is obfuscated and can have as many obfuscated variables as
I wish allocated to it then why worry... ;o)</p>
<p>Enjoy finding simple solutions to often very difficult problems...</p>
<p>Bazza...</p>
Basic Linux Menu (Bash)
2010-10-23T05:40:18-07:00Jonathan Fenechhttp://code.activestate.com/recipes/users/4169413/http://code.activestate.com/recipes/577437-basic-linux-menu/
<p style="color: grey">
Bash
recipe 577437
by <a href="/recipes/users/4169413/">Jonathan Fenech</a>
(<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/basic/">basic</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/menu/">menu</a>).
</p>
<p>A basic Linux menu which can do the following: </p>
<ul>
<li>Display Files and Directory's</li>
<li>Remove Files Displayed</li>
<li>Copy Files Displayed</li>
<li>Make Directory</li>
</ul>
How to detect the Linux distribution from an init.d script (Bash)
2010-03-16T13:24:22-07:00Gui Rhttp://code.activestate.com/recipes/users/4166241/http://code.activestate.com/recipes/576676-how-to-detect-the-linux-distribution-from-an-initd/
<p style="color: grey">
Bash
recipe 576676
by <a href="/recipes/users/4166241/">Gui R</a>
(<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/redhat/">redhat</a>).
Revision 2.
</p>
<p>There is no trivial way to know what Linux you are running. Red Hat, SuSE, etc., each distribution has a different way to tell what version is installed.</p>
A Shell, Binary To Hexadecimal To Decimal Demo... (Bash)
2013-01-11T18:31:03-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578413-a-shell-binary-to-hexadecimal-to-decimal-demo/
<p style="color: grey">
Bash
recipe 578413
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/decimal/">decimal</a>, <a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/hexadecimal/">hexadecimal</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/terminal/">terminal</a>).
</p>
<p>This little DEMO may be common knowledge to the big guns but not to amateurs like myself, so......</p>
<p>This is an Apple Macbbok Shell/Terminal DEMO shell script to show how to:-</p>
<p>1) Create a binary file...
2) Save it to your DEFAULT /directory/drwawer/folder/...
3) Display a hexadecimal dump of said binary file to prove that it is binary...
4) Select a single BYTE of that file and save it as an ASCII text decimal _number_, also to your DEFAULT /directory/drawer/folder/...
5) Read this ASCII text decimal number back in again...
6) Add this string representation to a number...
7) Stop...</p>
<p>It was intended purely for OSX 10.7.5 and above using the default terminal and shell...</p>
<p>It does work on many Linux flavours and shells/terminals also however.</p>
<p>Written so the anyone can understand what is going on.</p>
<p>The two files generated and saved in this DEMO to your DEFAULT /directory/drawer/folder/ are:-</p>
<p>BinaryString.dat
BinaryString.txt</p>
<p>This WILL lead to something very unusual in the not too distant future...</p>
<p>This is Public Domain and you may do with it as you wish...</p>
<p>Enjoy finding simple solutions to often very difficult problems...</p>
<p>Bazza, G0LCU...</p>
Better quote module for bash shells (Python)
2010-12-03T09:16:45-08:00Kevin L. Sitzehttp://code.activestate.com/recipes/users/4173535/http://code.activestate.com/recipes/577483-better-quote-module-for-bash-shells/
<p style="color: grey">
Python
recipe 577483
by <a href="/recipes/users/4173535/">Kevin L. Sitze</a>
(<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/escape/">escape</a>, <a href="/recipes/tags/logging/">logging</a>, <a href="/recipes/tags/quote/">quote</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/shell/">shell</a>).
</p>
<p>This Python module quotes a Python string so that it will be treated as a single argument to commands ran via os.system() (assuming bash is the underlying shell). In other words, this module makes arbitrary strings "command line safe" (for bash command lines anyway, YMMV if you're using Windows or one of the (less fine) posix shells).</p>
A utility like Unix seq (command-line), in Python (Python)
2017-01-08T17:48:57-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580744-a-utility-like-unix-seq-command-line-in-python/
<p style="color: grey">
Python
recipe 580744
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/seq/">seq</a>, <a href="/recipes/tags/sequence/">sequence</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/utility/">utility</a>).
</p>
<p>This recipe shows how to create a utility like Unix seq (command-line), in Python.
seq is described here: </p>
<p><a href="https://en.wikipedia.org/wiki/Seq_%28Unix%29" rel="nofollow">https://en.wikipedia.org/wiki/Seq_(Unix)</a></p>
<p>but briefly, it is a command-line utility that takes 1 to 3 arguments (some being optional), the start, stop and step, and prints numbers from the start value to the stop value, on standard output. So seq has many uses in bigger commands or scripts; a common category of use is to quickly generate multiple filenames or other strings that contain numbers in them, for exhaustive testing, load testing or other purposes. A similar command called jot is found on some Unix systems.</p>
<p>This recipe does not try to be exactly the same in functionality as seq. It has some differences. However the core functionality of generating integer sequences is the same (but without steps other than 1 for the range).</p>
<p>More details and sample output are here:</p>
<p><a href="https://jugad2.blogspot.in/2017/01/an-unix-seq-like-utility-in-python.html" rel="nofollow">https://jugad2.blogspot.in/2017/01/an-unix-seq-like-utility-in-python.html</a></p>
<p>The code is below.</p>
Bash Prompt Rainbow Color Chart (Bash)
2011-10-02T21:39:21-07:00userendhttp://code.activestate.com/recipes/users/4179007/http://code.activestate.com/recipes/577889-bash-prompt-rainbow-color-chart/
<p style="color: grey">
Bash
recipe 577889
by <a href="/recipes/users/4179007/">userend</a>
(<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/color/">color</a>, <a href="/recipes/tags/prompt/">prompt</a>, <a href="/recipes/tags/ps1/">ps1</a>, <a href="/recipes/tags/rainbow/">rainbow</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/terminal/">terminal</a>).
</p>
<p>This is a simple loop that displays a rainbow of different colors.</p>
Simple Bash Text Mode Sine Curve Generator. (Bash)
2014-08-12T20:57:39-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578921-simple-bash-text-mode-sine-curve-generator/
<p style="color: grey">
Bash
recipe 578921
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/cygwin/">cygwin</a>, <a href="/recipes/tags/graph/">graph</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/text/">text</a>).
Revision 2.
</p>
<p>This bash script is a taster for a kids level, audio, text mode, sweep generator.
The code just creates a single cycle of a quantised sine curve inside an 80 x 24 bash terminal.
This will be the calculator for a sinewave sweep generator from about 50Hz the 12KHz...
The code tells you more and the display is in comments at the end...</p>
A Building Block, Bash Binary File Manipulation... (Bash)
2013-01-29T22:07:57-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578441-a-building-block-bash-binary-file-manipulation/
<p style="color: grey">
Bash
recipe 578441
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/shell/">shell</a>).
Revision 2.
</p>
<p>Apologies for any typos, and IF this has been done before...</p>
<p>The code generates a 256 byte binary file of _characters_ 0x00 to 0xFF for general usage and generates another binary file manipulated in a basic way.</p>
<p>The for loops in the code are purely for DEMO purposes only.</p>
<p>This is Public Domain and you may do with it as you please. I have uploaded it elsewhere too...</p>
<p>Watch for wordwrapping, etc and read the code for more information...</p>
<p>Enjoy finding simple solutions to often very difficult problems...</p>
<p>Bazza, G0LCU...</p>
Print selected text pages to PDF with Python, selpg and xtopdf on Linux (Bash)
2014-10-29T17:38:10-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578954-print-selected-text-pages-to-pdf-with-python-selpg/
<p style="color: grey">
Bash
recipe 578954
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/reportlab/">reportlab</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/text_files/">text_files</a>, <a href="/recipes/tags/text_processing/">text_processing</a>, <a href="/recipes/tags/unix/">unix</a>).
</p>
<p>This recipe shows how to use selpg, a Linux command-line utility written in C, together with xtopdf, a Python toolkit for PDF creation, to print only a selected range of pages from a text file, to a PDF file, for display or print purposes. The way to do this is to run the selpg utility at the Linux command line, with options specifying the start and end pages of the range, and pipe its output to the StdinToPDF.py program, which is a part of the xtopdf toolkit.</p>
scan db to login the ssh servers (Bash)
2010-03-16T13:11:17-07:00J Yhttp://code.activestate.com/recipes/users/4170398/http://code.activestate.com/recipes/576877-scan-db-to-login-the-ssh-servers/
<p style="color: grey">
Bash
recipe 576877
by <a href="/recipes/users/4170398/">J Y</a>
(<a href="/recipes/tags/awk/">awk</a>, <a href="/recipes/tags/bash/">bash</a>).
Revision 2.
</p>
<p>awk with parameters passed from bash</p>
Arduino Diecimila Board Access Inside A Linux Bash Shell. (Text)
2011-03-30T18:08:11-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/577627-arduino-diecimila-board-access-inside-a-linux-bash/
<p style="color: grey">
Text
recipe 577627
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/access/">access</a>, <a href="/recipes/tags/arduino/">arduino</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/text/">text</a>).
</p>
<p>The "code" in this recipe is a step by step "root" shell command line procedure for testing whether a(n) USB
Arduino Dev Board is working or not. To get more recognisable characters displayed it is best to use a
potentiometer wired as one end to +5V, the other end to Gnd and thw wiper to ANALOG IN 0.
This has been tested on various Linux Distros and kept as simple as possible so that anyone can understand it.</p>
<p>The required ?.pde file for the Arduino Board can be found here:-</p>
<p><a href="http://code.activestate.com/recipes/577625-arduino-diecimila-board-access-inside-winuae-demo/?in=lang-python" rel="nofollow">http://code.activestate.com/recipes/577625-arduino-diecimila-board-access-inside-winuae-demo/?in=lang-python</a></p>
<p>It is issued entirely as Public Domain by B.Walker, G0LCU, 30-03-2011, and you may do with it as you please.</p>
<p>Similar assumptions are made as in the URL above.</p>
<p>Enjoy finding simple solutions to often very difficult problems... ;o)</p>
A simple shell script to keep the wife off of your back... (Bash)
2013-12-09T20:05:49-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578781-a-simple-shell-script-to-keep-the-wife-off-of-your/
<p style="color: grey">
Bash
recipe 578781
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/reminder/">reminder</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/shell/">shell</a>).
</p>
<p>How many times have you been asked to remember to do something from the other half whilst she is out for a short while.</p>
<p>For example: "You WILL check the dinner every few minutes won't you?"</p>
<p>And how many times did/do you forget?</p>
<p>Most of us have been there...</p>
<p>This is a simple kids level, practical learning, shell script that generates an "xterm" with your reminder inside every 30 seconds for a period of 3 seconds.</p>
<p>It is always be the active front window for 3 seconds at a time to _annoy_ you into remembering.</p>
<p>Usage: reminder "What you have to remember here using spaces AND double quotes."<CR></p>
<p>Just reanme the downloaded script to reminder and remember to chmod it as required.</p>
<p>Just run it from your default terminal and when finished press Ctrl-C just AFTER the xterm window closes.</p>
<p>There is NO error detection so steer clear of any special characters in you reminder text.</p>
<p>Enjoy finding simple solutions to often very difficult problems...</p>
A Bash Beep Command For OSX 10.7+... (Bash)
2014-02-27T19:36:17-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578837-a-bash-beep-command-for-osx-107/
<p style="color: grey">
Bash
recipe 578837
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/beep/">beep</a>, <a href="/recipes/tags/error_beep/">error_beep</a>, <a href="/recipes/tags/error_sound/">error_sound</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/sound/">sound</a>).
</p>
<p>This small bash script generates an 8044 byte 1KHz sinewave wave file and immediately plays it.
The file created is a _pure_ sinewave and lasts for 1 second. It uses the default "afplay"
command to run the generated file.</p>
<p>It was designed around an Apple Macbook Pro but using "aplay" it might even work on other *nix
flavours from the command line. I have not bothered to try it as this was purely for my MB Pro.</p>
<p>The wave file can be found as "/tmp/sinewave.wav" during the working session(s) and can be saved
anywhere of your choice.</p>
<p>Enjoy...</p>
<p>(Watch for word wrapping etc...)</p>
<p>Bazza.</p>
DEMO - Generate A Crude 1KHz Sinewave Using A BASH Script. (Bash)
2013-03-01T19:41:47-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578477-demo-generate-a-crude-1khz-sinewave-using-a-bash-s/
<p style="color: grey">
Bash
recipe 578477
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/sinewave/">sinewave</a>, <a href="/recipes/tags/sound/">sound</a>).
</p>
<p>A very simple crude sinewave generator using a BASH script inside a Linux Terminal.</p>
<p>The file required is generated inside the code and requires /dev/audio to work.</p>
<p>Ensure you have this device, if not the download oss-compat from your OS's repository...</p>
<p>It lasts for about 8 seconds before exiting and saves a 65536 byte file to your working directory/drawer/folder as sinewave.raw.</p>
<p>Use an oscilloscope to check the waveform generated...</p>
<p>It is entirely Public Domain and you may do with it as you please...</p>
<p>Enjoy finding simple solutions to often very difficult problems... ;o)</p>
<p>Bazza, G0LCU...</p>
Bash Script For An Oscilloscope... (Bash)
2013-06-19T19:06:50-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578570-bash-script-for-an-oscilloscope/
<p style="color: grey">
Bash
recipe 578570
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/anim/">anim</a>, <a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/audioscope/">audioscope</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/oscilloscope/">oscilloscope</a>, <a href="/recipes/tags/scope/">scope</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/sound_exchange/">sound_exchange</a>, <a href="/recipes/tags/sox/">sox</a>, <a href="/recipes/tags/terminal/">terminal</a>).
</p>
<p>This code is the latest as of 19-06-2013. It is an AudioScope designed around a Macbook Pro 13"
of which only has ONE microphone input. It works under Linux variants too. Read the code for
much more info.</p>
<p>It was my way of learning Bash scripting.</p>
<p>It is resident here at this site:-</p>
<p><a href="http://www.unix.com/shell-programming-scripting/212939-start-simple-audio-scope-shell-script.html" rel="nofollow">http://www.unix.com/shell-programming-scripting/212939-start-simple-audio-scope-shell-script.html</a></p>
<p>It started off as a fun idea and is now becoming a very serious project.</p>
<p>As it stands this is fully working but it is uncalibrated and this is where it will stay on this site.</p>
<p>As the above site is the host then all future uploads will be there...</p>
<p>To do list...</p>
<p>DC input. [1]
DC polarity. [1]
2 more Internal sync modes.
External triggering.
Zoom facility - if possible in text mode.
Vertical calibration. [2]
Frequency measurement. {3]
(Others.)</p>
<p>[1] I have simple HW built as an idea but yet to prove it...
[2] Preliminary HW built but not yet used. Calibration SW and circuit(s) to be built into script as it progresses.
[3] I already have a working script but not completely satisfied at it at this point...</p>
<p>I am noing to say much else except that it has already been given a 5 star rating on the above UNIX site...</p>
<p>As it stands this code is entirely Public Domian and you may do with it as you please...</p>
<p>Enjoy something completely different using Bash scripting...</p>
<p>Finally the code defaults to a DEMO mode which requires no HW access at all but everything is still functional...</p>
<p>__Thoroughly__ read the code for more information...</p>
<p>As a circuit is inside the script then it is best viewed in plan text mode.</p>
<p>Bazza, G0LCU.</p>