Bash Shell Scripting For Beginners - Local and Global Variables

preview_player
Показать описание
In This video I demonstrate the difference between local and global variables in bash, remember bash unlike most other languages has all its variables set to global by default. You can use the "local" flag to make the variable be accessible only by the function call.

******Source Code used in this video******
###local variables stay within the function, and cannot be accessed outside of it, to the rest of the script outside of that functions it's as if the variable doesn't even exist.

##by default all the variables in bash are global variables
function greet_user(){
local name=$1
echo "Hello $name how are you doing?"
}

###when the local flag is set the variable becomes "locked" to that function
#function greet_user(){
# local name=$1
# echo "Hello $name how are you doing?"
#}

name="George"
greet_user Kenny
echo "Hello $name how are you doing?"
#echo "after calling our function"
#echo "Hello $name How are you doing today?"
#echo "Hello $othername"
#greet_user

and be sure to click that notification bell so you know when new videos are released. ₿💰💵💲Help Support the Channel by Donating Crypto💲💵💰₿

Bitcoin
3MMKHXPQrGHEsmdHaAGD59FWhKFGeUsAxV

Ethereum
0xeA4DA3F9BAb091Eb86921CA6E41712438f4E5079

Litecoin
MBfrxLJMuw26hbVi2MjCVDFkkExz8rYvUF

Dash
Xh9PXPEy5RoLJgFDGYCDjrbXdjshMaYerz

Zcash
t1aWtU5SBpxuUWBSwDKy4gTkT2T1ZwtFvrr

Chainlink
0x0f7f21D267d2C9dbae17fd8c20012eFEA3678F14

Bitcoin Cash
qz2st00dtu9e79zrq5wshsgaxsjw299n7c69th8ryp

Etherum Classic
0xeA641e59913960f578ad39A6B4d02051A5556BfC

USD Coin
0x0B045f743A693b225630862a3464B52fefE79FdB
Рекомендации по теме
Комментарии
Автор

I've been looking to get a better understanding of more than just the bare minimum of Bash that I knew already, I was pretty happy to find that you have tutorials on it, you explain things very clearly. These should have more views like your newer videos, hopefully you do more of this kind of thing!

linuxatheist
Автор

Great video man. Really helped me understand.

NayeZen
Автор

Cool thank you.
I was surprised to learn that BASH behaves like that.
I mean I assumed that, well if I declare a variable inside a function it must be local...
But I start to see that BASH dosn't play well with my assumptions. BASH is something special... hahha ;)

limitless