Below you can find a short script on how to convert a binary number to decimal using python casting. Casting is when you convert variable from one type to another. In this case we use python casting to convert string to decimal number that is integer. Therefore, when you attempt to use casting to convert variable type to integer make sure that you variable type imput is a string. Create a following file with a following content:
#!/usr/bin/env python

while True:
        # Try to convert bunary to decimal
        decimal_num = int(raw_input("Enter a binary number: "), 2)
        # If we fail we ask again user to enter binary number
    except ValueError:
        print "Your input is not a binary number! Please try again."
        # Exit program if the conversion from binary to decimal was successful
# print converted decimal number
print decimal_num
Save your script as eg., make it executable and execute:
$ chmod +x
$ ./

Here a listed few of many ways how to extract number from a string. For all the examples below we will use sentence I am 999 years old. where the aim is to exctract nunber 999. Let's start by using tr command:
$ NUMBER=$(echo "I am 999 years old." | tr -dc '0-9')
$ echo $NUMBER

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'

In the following example we are going to show how to remove columns from CSV file based on the column number. Consider a following linux command separated file containing 10 columns:
$ cat temp.csv 

In this short config we will show a multiple options on how to remove a first line from a text file. Here is the content of our sample file.txt.
$ cat file.txt 

Probably the easiest way to count number of columns in CSV file using bash shell is simply count number of commas in a single row. In the following example the content of the file myfile.csv is:
$ cat myfile.csv 

To list all available that is installed packages for your GNU R installation, start GNU R:
$ R

R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-redhat-linux-gnu (64-bit)

The Bash "Shellshock" bug is used to spread malware using botnets. To make sure that you can prevent your system against Shellshock exploit make sure that your system is up to date. Once you update your system use below vulnerability test to help you find out whether your system is vulnerable to Bash Shellshock attacks.
Simply open a terminal on your Linux system and execute the following linux command
$ env i='() { :;}; echo Your system is Shellshock vulnerable' bash -c "echo Shellshock Linux system vulnerability test"
If your system is vulnerable to the Bash "Shellshock" bug the above command will produce a following output:

How can I retrieve yesterday date using bash?
$ date '+%A, %Y-%m-%d'
Saturday, 2014-06-28
$ date -d "yesterday" '+%A, %Y-%m-%d'
Friday, 2014-06-27

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"

Although Bash scripting is not a full fledged compile-able programming language, it is still very powerful and the script size can grow to enormous size. Therefore, even when you are just occasional bash scripting user or complete beginner some techniques is good to know in order to help debug you bash code. In this article we list some most command and basic bash scripting debbuging techniques.

The first debugging technique is bu using -x bash option during script execution. This will print all lines of code that is execute. For an illustration let's consider a following example:

echo hello

echo $myvar
To debug this bash shell script use -x bash option during script execution:
$ bash -x 
+ echo hello
+ myvar=3
+ echo 3

After reading this short shell scripting tutorial you will be able to to create and execute your own bash shell script. Not previous knowledge of shell scripting is required. However, you are expected to have some knowledge of hot ot start terminal and how to edit text files with some text editor of your choice.

Writing your own first Shell Script

In this section and as well as a first step we are going to create a simple shell script doing nothing else but printing "Shell Scripting" on the terminal output. This will will your starting point. To your first basic script together you need to know two things:

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.

Some Linux tools does not properly work with files which include spaces in their names. This simple bash for loop will remove white space from file names and rename/move for all files in the given directory.

Very often I need to upload some files to my web server from a command line. entering a user name and password, changing directory can be little tedious work. Here is a small bash script which make this work easier. This script first defines a variables such as hostname of the ftp server, username and password and then it creates ftp session and uploads file into your selected directory:

Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in: