Get count of lines in scripts (shell)

2015-10-15 1 min read bash
If you have tried to get the count of lines in file, the you would know about “nl” or “wc -l”. But as you are aware these give you number of lines with other details as well and you need to post process the number to make sure that you have only number and nothing else. In such cases, it is useful to use the count feature of grep and here is a shorthand to get the count of lines in any shell script: Continue reading

bash debug – log all executed commands

2014-02-03 1 min read bash
Screenshot of a Bash 3.1 session demonstrating its particularities. Shows exporting a variable, alias, type, Bash’s kill, environment variables PS1, BASH_VERSION and SHELLOPTS, redirecting standard output and standard error and history expansion. A POSIX session is launched from a normal session. Finally, the POSIX session kills itself (since just “exit” would be too boring). (Photo credit: Wikipedia) Whenever I am writing a script in perl or bash, I always wish that there Continue reading

bash – using the vi mode more effectively.

2013-11-22 1 min read bash
Vi blogging bundle (Photo credit: pedro mg) You can first set the bash mode to vi. This will enable some vim like features to bash. So, add this to .bashrc : set -o vi Once, you have done that then its time to get more out of the vi mode. First, check some things and set some interesting stuff. #Display all the bindings : bind -P #Copy the current bindings and use it in inputrc: bind -p |grep -v self-insert>~/. Continue reading

Shortcut to run current command with sudo in bash

2012-09-20 1 min read Fedora Linux
For me, I mostly forget to add “sudo” to the command until the time I am actually supposed to run it. Also sometimes, on some systems, bash completion does not work as expected with “sudo”. With these in mind, I wanted something such that when I have completed the command, I could insert sudo in the begining of the command without much ado. So, finally this is what I came up with in my “~/. Continue reading

Array of all possible colors in bash script

2012-05-07 1 min read bash Learning
Sometime back, we had looked at using colors in bash script and here is a way to create a array of all the colors. #!/bin/bash - #=============================================================================== # # FILE: colorarray.sh # # USAGE: ./colorarray.sh # # DESCRIPTION: # # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: Amit Agarwal (aka), amit.agarwal@roamware.com # COMPANY: Roamware India Pvt Ltd # CREATED: 16/04/12 17:24:09 IST # Last modified: Mon Apr 16, 2012 05:39PM # REVISION: --- #=============================================================================== count=0 for i in 40m 41m 42m 43m 44m 45m 46m 47m do for l in 0 1 do echo -n " Continue reading
Older posts