• 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
8 comments | 12:44 AM

Bash variables are defaults to global

What makes a variable local?

  • A variable declared as local is one that is visible only within the block of code in which it appears. It has local "scope." In a function, a local variable has meaning only within that function block.
    Ex:
    local variable name

func ()
{
local loc_var=23
# Declared as local variable.
# Uses the 'local' builtin.
echo "\"loc_var\" in function = $loc_var"
global_var=999

# Not declared as local.
# Defaults to global.
echo "\"global_var\" in function = $global_var"
}

func
# Now, to see if local variable "loc_var" exists outside function.

echo "\"loc_var\" outside function = $loc_var"

# $loc_var outside function =
# No, $loc_var not visible globally
.

echo "\"global_var\" outside function = $global_var"

# $global_var outside function = 999
# $global_var is visible globally
.
exit 0
  • Before a function is called, all variables declared within the function are invisible outside the body of the function, not just those explicitly declared as local

func ()
{
global_var=37

# Visible only within the function block
# before the function has been called.

} # END OF FUNCTION

echo "global_var = $global_var"
# global_var =
# Function "func" has not yet been called,
# so $global_var is not visible here.

func

echo "global_var = $global_var"
# global_var = 37 Has been set by function call.

  • Using the declare builtin restricts the scope of a variable

foo ()
{
FOO="bar"
}


bar ()
{
foo
echo $FOO
}

bar
# Prints bar

However . . .

foo (){
declare FOO="bar"
}
bar ()
{
foo
echo $FOO
}
bar
# Prints nothing.

8 comments:

  1. Very good article...Thanks

    ReplyDelete
  2. Well post its tell us how to make math diagrams with new method i really like this thanks for share it sop editing service .

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. It is very important that what you write.

    ReplyDelete
  5. Commonly we attain confused when we finally hear the exact terms website development service in addition to internet developer getting used interchangeably. But thoughts is broken done looking over this, all your individual confusions may perhaps disappear. Poof! kissmanga

    ReplyDelete
  6. http://www.bashguru.com/2009/08/gcd-of-more-than-two-numbers.html?showComment=1543883280359#c5987719078380583062

    ReplyDelete