Bash Shell Scripting for Beginners 2019 – Linux Environment Variables
- January 8, 2024
- Posted by: MainInstructor
- Category: Go
Video Title: Bash Shell Scripting for Beginners 2019 – Linux Environment Variables
What’s going on guys in today’s video we are going to discuss environment variables in Linux and UNIX based systems environment variables are just a set of dynamically named values stored within the system that are used by applications and commands launched by shells and subshells in simple words an
Environment variable is a variable that points to a value in our environment that will be of interest we can take a look at all of our environment variables on the system with a simple command that will print them to the screen that command is env and you can see we get a
Whole lot of text that is listed here now if Ian V doesn’t work on your system there’s another command you can do called print env and print env can also be used to print specific environment variables so for example if we just want to know what the user variable is we can
Do print env user and we get Kenny that is the value for our user variable but let’s go back to taking a look at all of them now the first thing that sticks out like a sore thumb is this big obnoxious block of text here called LS colors now this very bowl is
Pretty self-explanatory so it is the colors that show up whenever we do an LS so you’ll see in my system here JPEGs they get kind of this purple color text files they have this white color the executable files they get this green color directories have this blue color
And so on and so forth and when we take a look at what’s actually set inside of here we can see that the syntax is essentially star file extension equals and then some numbers now you should remember the star from some of my earlier videos you know
That a star is a wild card so whenever we see something like this we know that star dot mp4 applies to every single file regardless of its name that has the mp4 extension so what this is saying here is star mp4 equals this first set of numbers which I believe has
To do with some stylizing for the text so it has to do with whether the text is bold or not or whether it’s italicized or underlined anything like that and then the second text that comes after the semicolon the second number this has to do with the actual color so this
Number 35 that just corresponds to some color let me see I don’t actually have any MP fours in here but let’s see if we can find the jpg because I do have the jpg in here um let’s see let’s make this a little bit easier to look at print P
And V LS colors and let’s see do we see our jpg uh well I’m not gonna spend all day looking for it but anyway oh there it is okay 35 so 35 basically just corresponds to this kind of off purplish looking color there so let’s bring back
Up our environment variables and take a look at some other ones we have language so our language is us utf-8 this typically gets set whenever you’re installing your system we actually had to go in and set this manually in the Gentoo installation video that I did distros like Gentoo they require you
To set everything up manually but in a distro like Linux Mint or a bun – things like this would be set for you when you just pick the language out in the GUI box that it shows you all right when we come down a bit we see our user here
Kenny now like I told you in the beginning of this video these variables are dynamic meaning that they can change if I come over here and I were to spawn a root shell and I printed out my environment variables again you’ll see that the users no longer Kenny the user
Is now route because it was actually my root user that ran this command all right same thing with our present working directory so this is an environment variable that we’ve actually worked with before it’s one of the first commands that people learn on Linux so PWD just shows you the current
Directory the full path of it that you are in but if we were to go back a directory and then do print env you’ll see that now where was it present here it is present working directory you’ll see that now it has been changed to this new folder
Because of course we are in this new folder alright so let’s get back into our bash scripting folder now we can set our own custom environment variables if we want so you saw for example the present working directory there’s another one called home here which just
Refers to your home directory it can be useful to set environment variables for directories that you frequently go to because you can access them in your shell through the environment variable let me show you an example of that one home so right now you see that I’m currently in this bash scripting
Directory well if I did CD into the home variable which since it’s a variable we have to prepend it with a dollar sign and then type its name home you could see that it just sent me straight into my home folder inside of home kenning so
We can set that if we want to whatever directory we want now we’re not gonna actually change our home variable we’re gonna create a new variable so let’s do one for My Documents folder now the syntax to do this is just variable name equals and then my value so in order to
Do this with documents we’ll give it a name and we want to give it something pretty simple so we’ll just call it Docs equals and the location my documents folders home Kenney documents and of course we have to put it inside of our double quotes now you see that I put it
In all caps and that all these other environment variables are written in all caps you don’t necessarily have to do that I could make this be lowercase do X but I don’t recommend doing that and the reason why is because it’s just convention to set your environment
Variables to all caps there’s not really much else on a Linux system that’s gonna be all caps so if you did that as lowercase and you’re running a script on that system the shell might get confused it might think that lowercase do X is something else so you don’t have to make
It caps but it’s just a good idea to make a caps so we hit enter and now this environment variable is set meaning that we can go to it if we CD Docs and you see now I am inside of My Documents folder now keep in mind when
We set our environment variables in this way they are not persistent if I were to close out of these shells here and then pop another one and try to CD docks well it didn’t work and it didn’t work because when we set our variables that way they only last for the current
Session that you are in with that terminal so if I didn’t close that terminal Doc’s would have still been an environment variable it would have been an environment variable until the end of time or at least until I close that terminal tab if you want to set them
Permanently you have to define them inside of your bash RC file now we’re not going to go over that today because bash RC really could have a whole video unto itself there’s a lot of parameters to set in there especially around how your shell actually looks because if
You’re on a different system right now I’m logged into Linux Mint xfce you may notice that your color and the way that all of this is formatted may look different all of that is defined inside of bash RC which I’m gonna make a video about in the future but for now you guys
Learned about environment variables I hope you’re able to use this information to be more productive please leave a like on this video subscribe and share it with your friends you think might find a useful peace out
-
Sale!
Wireless WIFI Repeater Extender Amplifier Booster 300Mbps
$29.99$14.99 Add to cartWireless WIFI Repeater Extender Amplifier Booster 300Mbps
Categories: Electronics, Wi-Fi Router, Wireless Wi-Fi Extender Tags: 300Mbps, 802.11N, Amplifier, Booster, Extender, mobile wi-fi booster, Remote, WIFI, Wireless, Wireless WIFI, Wireless WIFI Repeater, Wireless WIFI Repeater Extender, Wireless WIFI Repeater Extender Amplifier, Wireless WIFI Repeater Extender Amplifier Booster, Wireless WIFI Repeater Extender Amplifier Booster 300Mbps$29.99$14.99 -
Sale!
Full RGB Light Design Gaming Headset Headphones with Mic
$24.99$14.99 Add to cartFull RGB Light Design Gaming Headset Headphones with Mic
Categories: Electronics, Gaming, Gaming Headsets Tags: Design, Full, Full RGB Light Design Gaming Headset, Full RGB Light Design Gaming Headset Headphones, Full RGB Light Design Gaming Headset Headphones with Mic, Gamer, Gaming, Gaming Headset Headphones, gaming headset wireless, Headphone, Headphones, Headset, Light, Mic, Package, RGB$24.99$14.99 -
Sale!
Wireless BlueTooth Multi-Device Keyboard Mouse Combo
$39.99$19.99 Add to cartWireless BlueTooth Multi-Device Keyboard Mouse Combo
Categories: Electronics, Gaming, Gaming Keyboards, Keyboard Mouse Combos Tags: Combo, Keyboard, keyboard mouse combos, Mouse, MultiDevice, Set, WireKeyboard Mouse Combo, Wireless, Wireless BlueTooth Keyboard Mouse Combo, Wireless BlueTooth Keyboard Mouse Combos, Wireless BlueTooth Multi-Device Keyboard Mouse Combo, Wireless BlueTooth Multi-Device Keyboard Mouse Combos$39.99$19.99 -
Sale!
High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
$199.99$139.99 Add to cartHigh Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
Categories: Gaming, Gaming Chairs Tags: Adjustable, Chair, computer chairs, Desk, Executive, Gaming, Girl, Headrest, High, High Back Leather Executive Adjustable Swivel Gaming Chair, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar, High Back Leather Executive Adjustable Swivel Gaming Chairs, Leather, Lumbar, Office, Racing, Swivel$199.99$139.99 -
Sale!
Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
$29.99$19.99 Select optionsProfessional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
SKU: N/A Categories: Electronics, Gaming, Gaming Headsets Tags: Cancelling, Gaming, Gaming Headphones with Noise Cancelling Microphone, gaming headset, Headphones, Headset, LED, Light, Mic, Microphone, Noise, Professional, Professional LED Light Wired Gaming Headphones, Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone, Wired, Wired Gaming Headphones, Wired Gaming Headphones with Noise Cancelling Microphone$29.99$19.99 -
Sale!
Gaming Desk with LED Lights USB Power Outlets and Charging Ports
$349.99$249.99 Select optionsGaming Desk with LED Lights USB Power Outlets and Charging Ports
SKU: N/A Categories: Computer Desk, Gaming, Gaming Desk Tags: and Charging Ports, Charging, Desk, Desks, Gaming, gaming desk with led lights, Gaming Desks with LED Lights, Home, LED, Lights, Monitor, Office, Outlets, Port, Power, Room, Stand, USB, USB Power Outlets, White, Workstation$349.99$249.99 -
Sale!
Wired Mixed Backlit Anti-Ghosting Gaming Keyboard
$99.99$79.99 Add to cartWired Mixed Backlit Anti-Ghosting Gaming Keyboard
Categories: Electronics, Gaming, Gaming Keyboards Tags: Antighosting, Backlit, Blue, brown, Gaming, Gaming Keyboard, gaming keyboards, gaming keyboards and mouse, Keyboard, Laptop, Switch, Wired, Wired Mixed Backlit Anti-Ghosting Gaming Keyboard, Wired Mixed Backlit Anti-Ghosting Gaming Keyboards, Wired Mixed Backlit Gaming Keyboard$99.99$79.99 -
Sale!
Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
$119.99$59.99 Add to cartWireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
Categories: Electronics, Gaming, Gaming Headsets Tags: 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, ANC, Audio, Bluetooth, Cancellation, Ear, Earphone, gaming headset, Headphones, Headset, Hi-Res Over the Ear Headphones Headset, HiRes, Noise, Wireless, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Headphones, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headsets$119.99$59.99 -
Sale!
Wired Sports Gaming Headset Earbuds with Microphone
$19.99$9.99 Select optionsWired Sports Gaming Headset Earbuds with Microphone
SKU: N/A Categories: Gaming, Gaming Headsets Tags: Accessories, Earbud, Earphone, Earphones, Gaming, gaming headset with microphone, Headphones, Headset, IOS, Microphone, Sports, Wired, Wired Sports Gaming Headset Earbuds, Wired Sports Gaming Headset Earbuds with Microphone, Wired Sports Headset Earbuds$19.99$9.99 -
Sale!
150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
$49.99$29.99 Add to cart150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
Categories: Charging Stations, Electronics Tags: 150W, 150W Charging Station, 150W Universal Multi USB Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Stations, 150W Universal Multi USB MAX Charging Station, 16 Port MAX Charging Station, 3.5A, Charger, Charging, Fast, laptop charging stations, Max, Multi, Port, Stand, Station, Universal, USB$49.99$29.99
Great. Tq.
love this series, its helping me to get into bash scripting fast!
Thats cool