If you are on a POSIX compliant machine (OSX or Linux) you can make use of Shell Scripts to do day-to-day donkey work. I use Shell Scripts for backups, cleaning out temporary folders, profiling and logging. Writing these scripts is pretty straightforward and if you are completely new to it I recommend getting a copy of Classic Shell Scripting.
Recently I came across a couple of shortcuts that have greatly reduced the time it takes to write a script in the vi editor.
Using :! from within vi you can run a shell command. This is great as you don’t need to exit vi to test your code. Let’s say for example your script is called myscript.sh. You can run your script from within the vi editor by using.
Furthermore you can make more changes in vi, save the file and then run the script again by using
This is a shortcut to the last command issued to the shell, allowing you to retest your shell script without even typing the filename.
Within vi the % variable refers to the file that you are currently editing. So to run the script you are editing from within vi you can also use:
Have an update or suggestion for this article? You can edit it here and send me a pull request.
Listening to BBC Radio with mpv
The BBC publishes high quality 320 kbps HLS AAC streams that can be used to listen to radio from the command-line using mpv. Here are the URLs and some aliases to start listening quickly.
Vim: So long Pathogen, hello native package loading
Vim 8 added a native way to load third-party packages. This means, for me at least, there is no longer any need to use a third party plugin helper like Pathogen.
Linux and Unix more command tutorial with examples
Tutorial on using more, a UNIX and Linux command for viewing the contents of a file or files one screen at a time. Examples of viewing a file, viewing multiple files, searching using regular expressions and opening the file in a text editor.