• Welcome to Bashguru

    Linux is one of popular version of UNIX operating System. It is open source as its source code is freely available. It is free to use. Linux was designed considering UNIX compatibility. It's functionality list is quite similar to that of UNIX and become very popular over the last several years. Our Basic motive is to provide latest information about Linux Operating system.

  • Python Programming

    Python is a comparatively simple programming language, compared to c++. Although some of the benefits of c++ are abstracted away in python, they are replaced with an overall easier to learn language with many “intuitive” features. For this reason it is common and recommended by most professionals that people new to programming start with python.

  • Perl Programming

    Perl is an open-source, general-purpose interpreted programming language. Used often for CGI, Perl is also used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications. The Perl languages borrow features from other programming languages including C, shell scripting (sh), AWK, and sed. They provide powerful text processing facilities without the arbitrary data-length limits of many contemporary UNIX command line tools, facilitating easy manipulation of text files.

  • Android

    Android is an operating system based on the Linux kernel, and designed primarily for touch screen mobile devices such as smart phones and tablet computers. Android is a Linux-based software system, and similar to Linux, is free and open source software. This means that other companies can use the Android operating developed by Google and use it in their mobile devices.Android gives you a world-class platform for creating apps and games for Android users everywhere, as well as an open marketplace for distributing to them instantly.

Saturday, June 21, 2008

Posted by venu k
1 comment | 12:24 AM
Unlike many other programming languages, Bash does not separate its variables by "type". Essentially, Bash variables are character strings, but, depending on context, Bash permits integer operations and comparisons on variables. The determining factor is whether the value of a variable contains only digits.
Integer or string?
# Integer.
let "a += 1"
echo "a = $a "
# a = 2335
# Integer, still.

# Substitute "BB" for "23".
# This transforms $b into a string
echo "b = $b"
# b = BB35
declare -i b
# Declaring it an integer doesn't help.
echo "b = $b"
# b = BB35

let "b += 1"
# BB35 + 1 =
echo "b = $b"
# b = 1
echo "c = $c"
# c = BB34
# Substitute "23" for "BB".
# This makes $d an integer
echo "d = $d"
# d = 2334
let "d += 1"
# 2334 + 1 =
echo "d = $d"
# d = 2335
# What about null variables?
echo "e = $e"
# e =
let "e += 1"
# Arithmetic operations allowed on a null variable?
echo "e = $e"
# e = 1
# Null variable transformed into an integer.

# What about undeclared variables?
echo "f = $f"
# f =
let "f += 1"
# Arithmetic operations allowed?
echo "f = $f"
# f = 1
# Undeclared variable transformed into an integer.

The burden is on the programmer to keep track of what type the script variables are.
Bash will not do it for you.
But “declare” or “typeset “built-ins permit restring the properties of variables.
This is very weak form of the typing available in certain programming languages

declare –i number
# The script will treat subsequent occurrences of “number” as an integer
echo “Number = $number”
# Number = 3
echo “Number = $number”
#Number = 0
#Tries to evaluate the string “three” as an integer

1 comment:

  1. Thanks for a great article. Your tips are accurate and they will be of great help to me. I bookmarked your site, will be back ! !