Exit codes for Ruby scripts Oct 15 2018
One of the most common mistakes I see in ruby scripts is the lack of good exit status, this prevents the script from being trusted in composition with other commands. The purpose of this post is to explain why exit codes are important and how to use them on our scripts.
Bash Beyond Basics Increase your efficiency and understanding of the shell
If you are interested in this topic you might enjoy my course Bash Byond Basics. This course helps you level up your bash skills. This is not a course on shell-scripting, is a course on improving your efficiency by showing you the features of bash that are seldom discussed and often ignored.
Read More...Shell friendy Ruby scripts Sep 24 2018
When we build Ruby scripts, generally, we build them to be run independently but being able to compose them with other scripts makes them even better. How can we make our Ruby scripts be easy to compose? This is what this post is about, I will show you how to build your scripts so they can be composed or used independently.
Let’s see a basic Ruby script that receives a list of files and displays all lines capitalized.
Read More...Ruby one-liner scripts Sep 17 2018
Ruby excels in its simplicity. It allows programmers to go from idea to implementation in a short time without much overhead. While many programmers have only heard of Ruby in relation to the web framework Rails, the scripting side of Ruby is very interesting and a rewarding use of the language. In this post, I will show you how to use Ruby to build one-liner scripts, and I will explain some useful flags when using Ruby scripts to process text.
Read More...Using Thor and Ruby to build a CLI Sep 10 2018
Thor is a toolkit that can help us build command line interfaces(CLIs). You can find many tutorials on how to build a basic CLI using Thor. I want to explain the default behaviour of Thor and also when to use env to define the binary that will run your script.
We normally build custom scripts to automate tasks on our servers or local environments. Often these scripts require many flags or a big list of parameters. If the number of flags and parameters (from now on, options) are small then we won’t have a problem building the logic to handle them. However, when there are a number of options or we want to handle aliases, e.g. accepting the flag –delete or -d as the same operation, then things can become harder and more tedious to maintain.
Read More...Find command for the million Jul 29 2018
One of the most useful Unix commands, and mostly underutilized, is find. To get the most out of it there are two key features that we need to explore and understand.
- How to iterate over the results
- Limitation on the number of results we can operate on
Learn by doing
Lets create a few files and directories to use as examples:
Read More...Bash prompt customization Jul 16 2018
Bash when is executed as interactive, uses environment variables to define how the shell prompt looks in different scenarios. One of those variables is PS1, this variable is used to define the prompt displayed when the shell is ready to read a command(this is the one we will normally refer to when we say we would like to customize our prompt).
There are more variables like: PS2 is displayed when the shell needs more input to complete a command, or PS0 that is displayed after it reads a command but before it is executed. But we will only focus on PS1 just now, there is more information on the man page of bash (run the command man bash and search for PS1).