How to test for null or empty variables within Bash script

The following bash script example we show some of the way how to check for an empty or null variable using bash:


if [ -z "$1" ]; then
    echo "Empty Variable 1"

if [ -n "$1" ]; then
    echo "Not Empty Variable 2"

if [ ! "$1" ]; then
    echo "Empty Variable 3"

if [ "$1" ]; then
    echo "Not Empty Variable 4"

[[ -z "$1" ]] && echo "Empty Variable 5" || echo "Not empty Variable 5"

Read more

SyntaxError: Non-ASCII character – Python with UTF-8 encoding


My Python program produce a following error message upon execution:

 SyntaxError: Non-ASCII character '\xc4' in file on line 1, but no encoding declared; 


Normally the above error message is displayed by python when other characters other then ASCII are used withing your code. The solution is to either remove all non-ASCII characters or include the bellow line into your code to enable UTF-8 encoding:

# - *- coding: utf- 8 - *-

Read more

How to obtain an user input with Python raw_input function example

The Python raw_input() function is used to read a string from standard input such as keyboard. This way a programmer is able to include user inserted data into a program. Let’s start with a simple example using python script to ask for an user name.

print "What is your name?"
name = raw_input()
print "Hello %s!" % name

First, we print string What is your name? telling the user what we expect him to input. Next, using the raw_input() function the standard input is assigned to a variable name. Lastly, we print the value of variable name to standard output.

$ python 
What is your name?
Monty Python
Hello Monty Python!

Read more

Check your GMAIL inbox for new emails with Bash script

In case you wish to automate your things with your gmail email. Here is a simple script on how to access your gmail account with bash script. Before you run the script make sure that curl command is available on your system as this script depends on it. The below script is a great way to quickly check your gmail inbox with a single command. Open your favorite text edit and create a bash script file with some arbitrary file name eg.


curl -u $username:$password --silent "" |  grep -oPm1 "(?<=<title>)[^<]+" | sed '1d'

Read more

How to access and print command line arguments with Python

The following is an example on how to pass and access command line arguments which a Python script. Save the following python script to a file eg.

from sys import argv

name, first, second, third, fourth = argv

print "Script name is:", name
print "Your first argument is:", first
print "Your second argument is:", second
print "Your third argument is:", third
print "Your fourth argument is:", fourth

# Alternatively we can access "argv" argument list directly using range. For exmaple:

# Print all arguments except script name
print argv[1:]

# Print second argument
print argv[2]

# Print second and third argument
print argv[2:4]

# Print last argument
print argv[-1]

Read more

Extract all URLs using Beautiful Soup and Python3

The following link will extract all URL’s for a given web page.

#!/usr/bin/env python3

# Python Version:  3.4.2
# bs4 version: 4.3.2-2

from urllib.request import urlopen
from bs4 import BeautifulSoup

html = urlopen("") # Insert your URL to extract
bsObj = BeautifulSoup(;

for link in bsObj.find_all('a'):

Read more

How to fill all empty valued cells within a CSV file with sed and bash shell

The following bash script can be used to fill empty cells within a CSV file. We assume that your file is evenly distributed so that it contains same number of columns in each row separated by comma. If your file is TABseparated use a following linux command to convert it to comma separated value file before you proceed.

$ cat test 
1       2       4       4
2       3       3       3
$ sed 's/\t/,/g' test 
$ cat test | tr '\t' ','

Read more

Writing a C style bash for loop – example

If you are stubborn C programmer and wish to get your way when using BASH you will be happy to know that BASH offers C style syntax for writing for loops. Below you can find two examples of C style bash for loop:

Simple c-style bash for look with three iterations:

for ((i=1; i <= MAX ; i++)) ; do
	echo "$i"

Read more

-bash: /bin/rm: Argument list too long – Solution


This error message appears when you try to remove, move or copy a long list of files. When using your shell a command can only accept a limited number of arguments. When the number of arguments supplied to the command exceeds the permitted number of arguments an error message will appear:

-bash: /bin/rm: Argument list too long

linux command to find your limit for maximum arguments:

# getconf ARG_MAX


# rm *
-bash: /bin/rm: Argument list too long

Read more

C programming tutorial

This series of articles is dedicated to development on Linux systems.

This tutorial focuses on C programming and covers such concepts as types, operators and variables, flow control, functions, pointers and arrays, structures, basic I/O, coding style and building a program as well as packaging for Debian and Fedora or getting a package in the official Debian repository.

Read more