Tuesday, 5 June 2012

Bash Script : Iterate over command line arguments

Below is simple bash script to calculate the average of integer numbers passed to the script from the command line arguments.

$#  - give the value of total number of argument passed to the script
$@ - using this we can  Iterate over command line arguments.

$ cat average.sh
#!/bin/bash

SUM=0
AVERAGE=0
ARG=$#
for var in "$@"; do
        if [ "$var" -eq "$var" 2>/dev/null ]; then
                if (( "$var" == 0 || "$var" > 100 )); then
                        echo "Invalid entry (ignored): $var"
                        ARG=$(($ARG-1))
                else
                        SUM=$(($SUM+$var))
                fi
        else
                echo "Invalid entry (ignored): $var"
                ARG=$(($ARG-1))
        fi
done
echo
AVERAGE=$(($SUM/$ARG))
echo "Average is : $AVERAGE"
echo

Output: 
$./average.sh 2 2 3.4 2 2 4.5 1001 0
Invalid entry (ignored): 3.4
Invalid entry (ignored): 4.5
Invalid entry (ignored): 1001
Invalid entry (ignored): 0

Average is : 2


Feel free to modify or use this script.

Creating Labels and Business Cards - gLabels

gLabels is a program for creating labels and business cards for the GNOME desktop environment. It is designed to work with various laser/ink-jet peel-off label and business card sheets that you'll find at most office supply stores. gLabels is free software and is distributed under the terms of the GNU General Public License (GPL).

Installing Glabels:
Glabels package is available in the default available repository under Ubuntu, you can search "Glabels" and install it using Software Center or can install it using command:
sudo apt-get install glabels
After successful installation, you can open the glabels application from Unity 'Dash'

Continue Reading...

Monday, 4 June 2012

Bash Script: Read the passwod without showing on the screen

Here is an simple bash script which reads the password value from a user and does not show the same on the screen.

Feel free to modify and use this script.

Source:
$ cat readpass.sh 

#!/bin/bash
echo -n "Enter your username: ";
read username
echo -n "Enter your passwd: "
read -s passwd
echo
echo "$username, your passwd is $passwd";

Output:  
$ ./readpass.sh
Enter your username: nikesh
Enter your passwd:
nikesh, your passwd is linuxpoison


Powerful Text Editor for Markdown and reStructuredText - ReText

Markdown is a text-to-HTML conversion tool for web writers. Markdown allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML).

Thus, “Markdown” is two things:
 * A plain text formatting syntax
 * A software tool, written in Perl, that converts the plain text formatting to HTML.

reStructuredText is an easy-to-read, what-you-see-is-what-you-get plain text markup syntax and parser system. It is useful for in-line program documentation (such as Python docstrings), for quickly creating simple web pages, and for standalone documents. reStructuredText is designed for extensibility for specific application domains. The reStructuredText parser is a component of Docutils.
Continue Reading...

 
//PART 2