Understanding Variables on the Linux Command-Line

Поділитися
Вставка
  • Опубліковано 9 чер 2024
  • The Linux Crash Course series here on Learn Linux TV teaches you a valuable Linux-related skill in each and every video. You can watch most episodes in any order, and with over 60 entries in this series (and counting) there's no shortage of Linux Learning! In this episode, Jay will teach you all about shell variables.
    Free Bash Scripting Course!
    Check out my brand-new Bash scripting series for free right here on UA-cam ➜ linux.video/bash
    Thanks to Akamai for sponsoring this video!
    Support Learn Linux TV by spinning up your own Linux server on their cloud platform ➜ learnlinux.link/akamai
    Brand LPI Linux Essentials Course Available
    Check out the new course on Udemy! ➜ learnlinux.link/lpi-course
    ➜ learnlinux.link/lpi-course
    Check out the Linux Shop
    In the official shop, you'll find Shirts, hats, stickers, bags and more!
    ➜ merch.learnlinux.tv
    5% discount on LPI exam vouchers
    After you finish Jay's new course, get 5% off an LPI exam voucher here:
    ➜ learnlinux.link/lpi-voucher
    Become a Patron
    Show your support for Learn Linux TV on Patreon and get access to exclusive perks!
    ➜ learnlinux.link/patron
    Become a Channel Member
    Show your support for Learn Linux TV here on UA-cam and get access to exclusive perks!
    ➜ learnlinux.link/member
    Mastering Ubuntu Server: 4th Edition
    Jay's latest book covers everything you need to know in order to master Ubuntu Server. It's available here:
    ➜ ubuntuserverbook.com
    Linux Gear and Kits
    Check out Jay's choice of hardware products, audio/video equipment, and more.
    ➜ learnlinux.link/amazon
    Grab an awesome Pi-powered KVM
    Support Learn Linux TV and grab yourself a TinyPilot KVM here:
    ➜ learnlinux.link/tinypilot
    Note: Royalties and/or commission is earned from each of the above links
    Time Codes
    00:00 - Intro
    00:46 - Set up your own Linux server with Akamai! (Sponsor)
    01:58 - Revisiting the echo command
    02:45 - Creating a variable in Bash
    03:11 - Printing the contents of a variable
    08:54 - Understanding Environment Variables
    12:19 - Capturing the output of a command into a variable
    15:22 - Capturing the current date into a variable
    Full Courses from Learn Linux TV
    • Linux Crash Course series ➜ linux.video/cc
    • Learn how to exit use tmux ➜ linux.video/tmux
    • Learn how to use vim ➜ linux.video/vim
    • Bash Scripting Series ➜ linux.video/bash
    • Proxmox VE Cluster Full Course ➜ linux.video/pve
    • Learn Ansible ➜ linux.video/ansible
    Linux-related Podcasts
    • Enterprise Linux Security ➜ enterpriselinuxsecurity.show
    • The Homelab Show ➜ thehomelab.show
    Learn Linux TV on the Web
    • Main site ➜ www.learnlinux.tv
    • Community ➜ community.learnlinux.tv
    • Enterprise Linux Security Podcast ➜ enterpriselinuxsecurity.show
    • The Homelab Show Podcast ➜ thehomelab.show
    • Content Ethics ➜ www.learnlinux.tv/content-ethics
    • Request Assistance ➜ www.learnlinux.tv/request-ass...
    Disclaimer
    Learn Linux TV provides technical content that will hopefully be helpful to you and teach you something new. However, this content is provided without any warranty (expressed or implied). Learn Linux TV is not responsible for any damages that may arise from any use of this content. The person viewing Learn Linux TV's content is expected to follow their best judgement and to make their best decisions while working with any related technology. Always make sure you have written permission before working with any infrastructure. Also, be sure that you're compliant with all company rules, change control procedures, and local laws.
    #CloudComputing #DevOps #Linux
  • Наука та технологія

КОМЕНТАРІ • 34

  • @sidheart8905
    @sidheart8905 5 місяців тому +2

    i am professional with 11 year experience but i still love your all videos and keep watching them daily the way you explain basics... just addicted for learning.

  • @12Q46HPRN
    @12Q46HPRN 5 місяців тому +7

    Outstanding!
    Thank you so much for your videos. I always learn something from you. I knew quite a bit about shell variables and even the env command. I've used the $(command) before, but more as a script-kiddie (copy/pasting what I've seen others doing online) and never knew that it opened up a sub-shell to run the command within the parentheses.
    Please keep up the good work!

  • @Akaterial
    @Akaterial 4 місяці тому +1

    Great video. I watched it last month when it was new. It came back to me as I was moving a bunch of files and directories around. Typing out directory names can be tedious even with autocomplete. I used what I learned in this video to create variables of the directory paths. It instantly made things so much easier. I could not only copy things around faster, I could also move around to the directories I stored in variables faster.

  • @Xenonandplutonium
    @Xenonandplutonium 5 місяців тому +2

    Pretty cool how I was learning about Python variables and you dropped this. This is cool. I feel like I can really get things more organized.

  • @lorensims4846
    @lorensims4846 5 місяців тому +3

    Don't sweat the ALL CAPS. Many early computers (and in fact the first typewriter) used only all caps.
    Using lowercase or mixed-case letters tends to complicate things.
    Merry Christmas!

  • @dylananderson7658
    @dylananderson7658 5 місяців тому

    Amazing explanation, thank you!

  • @SnowTheParrot
    @SnowTheParrot 5 місяців тому

    Another great episode

  • @BenChnobli
    @BenChnobli 5 місяців тому +1

    Thanks

  • @brhend
    @brhend 5 місяців тому

    Thank you

  • @juliusmilo5959
    @juliusmilo5959 5 місяців тому +1

    Thank You...

  • @TheGeekYT
    @TheGeekYT 5 місяців тому

    Thanks!

  • @zeppelinmexicano
    @zeppelinmexicano 4 місяці тому

    It should be interesting to see how this subshell-capture trick will work with some output more sophisticated than "ls" and all that. If it can actually capture htop in any meaningful way it would be handy to grab it for log purposes. Dunno, but there is a lot to test.

  • @mihai6564
    @mihai6564 5 місяців тому

    good video

  • @bramfran4326
    @bramfran4326 5 місяців тому +3

    Why do newlines disappear inside the variable at 13:30? That does not seem very consistent, imagine if other things you don't know (obviously not normal characters??) could also disappear.

    • @IcarusSparry
      @IcarusSparry 5 місяців тому +1

      The newlines are still in the variable, except for the very last one. The problem I have with this video is that you always (except when you don't, but that is very rare) want to use variables inside double quotes. So if our host had used
      echo "$file_list"
      we would have seen the output in the way that was expected. To dive a little deeper, if the variable is used outside double quotes then it is split into words, and the echo command outputs each word it is given separated by a space. This also means that multiple spaces and tabs get removed, and then echo puts a single space back.
      msg="Hello World"
      echo $msg
      Hello World
      echo "$msg"
      Hello World
      Bash does have sub-shells, which are created with "(" and ")". The thing that is created with "$(" and ")" is a different concept called "command substitution".
      Whilst this is clearly an introductory video, I think that with a length of 18 minutes it could also mention arrays. The syntax for them is fairly horrible but they needed to be added in a reasonably backward compatible manner.

  • @Shocker99
    @Shocker99 5 місяців тому +1

    6:40 You should have ls'd a directory with something in it for this example.

  • @tanuj05
    @tanuj05 5 місяців тому

    Nice video , did not know about sub shell

  • @x91w
    @x91w 5 місяців тому +3

    Is it OK to download say your bash course videos as a reference to use offline? If not where can I purchase a licence?

    • @ciscornBIG
      @ciscornBIG 5 місяців тому

      I've downloaded all learn Linux tv. UA-cam-dl

  • @adrmantap6508
    @adrmantap6508 5 місяців тому +1

    What ur font name please?,

  • @majstorgile
    @majstorgile 5 місяців тому

    👏👏👏

  • @Shriramkrishnhari
    @Shriramkrishnhari 5 місяців тому

    👍

  • @pmpartners
    @pmpartners 5 місяців тому

    If I want a variable to be available every time I open bash, is there a way to persist them?

    • @gumse666
      @gumse666 5 місяців тому +4

      If you declare it in .bashrc it will be available in every new terminal session (you have start a new terminal after you add your command to se the variable)

    • @pmpartners
      @pmpartners 5 місяців тому

      @@gumse666 Thank you! I’ll give it a try.

  • @ujjawalsinha8968
    @ujjawalsinha8968 5 місяців тому

    Why do we call Shell a "Shell". Is it because of the concept of "Sub-Shells"?

    • @tschorsch
      @tschorsch 5 місяців тому +4

      Because it's a shell around the OS, i.e. the outermost layer that a user interacts with. Shells can be command line or graphical.

  • @sotecluxan4221
    @sotecluxan4221 5 місяців тому

  • @suhas_joshi
    @suhas_joshi 5 місяців тому

    Sir add some videos with no-ip server setup

  • @ZubairKhan-vs8fe
    @ZubairKhan-vs8fe 5 місяців тому

    Please help. Why does Linux need a command line and a shell. Windows stopped using DOS ages ago

    • @teecount1
      @teecount1 5 місяців тому +1

      powershell on windows?
      To answer your question: It is usefull, if you do not want to do things yourself and want to have full control over the system.

    • @motoryzen
      @motoryzen 5 місяців тому

      Need? That depends
      If a program isn't launching at all or isn't launching correctly ( be it Linux , Mac, or Windows ) you can launch that program via a command prompt or terminal and you can then SEE....WHY.
      ;)
      Another scenario = a script that can completely setup and install all programs in your PC if you ever need to do a clean install ...starting over....and in the end..save literally...DAYS of work doing it all manually by hand.
      Instead...you'll end up doing it manually by hand.....once maybe twice..and make notes into the script.
      These are just a few of the many good scenarios where a command line and/or shell can be invaluable.

  • @palodoxaliqua5809
    @palodoxaliqua5809 5 місяців тому

    That path-variable had a / at the end. I therefore expected $mydir/hello.txt to have two / before the file name and throw an error because of the invalid path.
    Seems like linux ignores unnecessary slashes - interesting curiosity.

  • @theshowmanuk
    @theshowmanuk 5 місяців тому

    Thanks