How To Use Shell Environment Variables

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.ย. 2021
  • In this video, I am going to give a cursory introduction to shell environment variables, which come in two forms: global variables and local variables. I also discuss some of the global variables that I often use, including the PATH variable and how to add to the PATH.
    REFERENCED:
    ► www.gnu.org/software/bash/man... - Bash Reference Manual
    WANT TO SUPPORT THE CHANNEL?
    💰 Patreon: / distrotube
    💳 Paypal: www.paypal.com/cgi-bin/webscr...
    🛍️ Amazon: amzn.to/2RotFFi
    👕 Teespring: teespring.com/stores/distrotube
    DONATE CRYPTO:
    💰 Bitcoin: 1Mp6ebz5bNcjNFW7XWHVht36SkiLoxPKoX
    🐶 Dogecoin: D5fpRD1JRoBFPDXSBocRTp8W9uKzfwLFAu
    📕 LBC: bMfA2c3zmcLxPCpyPcrykLvMhZ7A5mQuhJ
    SOCIAL PLATFORMS:
    🗨️ Mastodon: distrotoot.com/@derek
    👫 Reddit: / distrotube
    📽️ LBRY/Odysee: odysee.com/$/invite/@DistroTu...
    DT ON THE WEB:
    🕸️ Website: distrotube.com/
    🐿️ Gemini Capsule: gemini://distro.tube
    📁 GitLab: gitlab.com/dwt1
    FREE AND OPEN SOURCE SOFTWARE THAT I USE:
    🌐 Brave Browser - brave.com/dis872
    📽️ Open Broadcaster Software: obsproject.com/
    🎬 Kdenlive: kdenlive.org
    🎨 GIMP: www.gimp.org/
    🎵 Ardour: ardour.org/
    💻 VirtualBox: www.virtualbox.org/
    🗒️ Doom Emacs: github.com/hlissner/doom-emacs
    Your support is very much appreciated. Thanks, guys!
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 113

  • @Neucher
    @Neucher 2 ปีที่แล้ว +61

    Yes, please more videos on these UNIX/POSIX standards, whatever you call these.

  • @littlepeon
    @littlepeon 2 ปีที่แล้ว +59

    Random gives a number between 0-32767 as 32768 is notable in computer science for being the absolute value of the maximum value of a 16-bit signed integer.

    • @michaelhoefler5118
      @michaelhoefler5118 2 ปีที่แล้ว +1

      Or just the largest value of an unsigned 16-bit integer 🙃

    • @rcht9586
      @rcht9586 2 ปีที่แล้ว +5

      @@michaelhoefler5118 no, a 16 bit unsigned integer has values from 0 to 65535

    • @johanngambolputty5351
      @johanngambolputty5351 2 ปีที่แล้ว

      32767 = 2^15 - 1 = sum of 2^n from 0 to 14 inclusive. Silly question though, why don't they use an unsigned int? Since RANDOM output is always positive anyway

    • @sukhmandersingh4306
      @sukhmandersingh4306 2 ปีที่แล้ว +3

      @@michaelhoefler5118 largest value of 16 bit *signed integer.

    • @michaelhoefler5118
      @michaelhoefler5118 2 ปีที่แล้ว

      @@rcht9586 yes! You are right. My bad!

  • @PinakiGupta82Appu
    @PinakiGupta82Appu 2 ปีที่แล้ว +29

    Quite useful info. Most Linux beginners will find your video super helpful to understand the basics of Environment Variables whether they use the command line regularly or occasionally.

  • @agustinranieri
    @agustinranieri 2 ปีที่แล้ว +22

    Daniel: echo $VAR
    The cooler Daniel: printenv VAR

    • @sukhmandersingh4306
      @sukhmandersingh4306 2 ปีที่แล้ว

      It's the other way around. All the cool kids do echo $VAR.

    • @agustinranieri
      @agustinranieri 2 ปีที่แล้ว +2

      printenv's rarity makes it cooler (?)

  • @Phydoux2112
    @Phydoux2112 2 ปีที่แล้ว +9

    The PATH stuff was getting to me. I have been wanting to dig deeper into this but never did. Your short and sweet description on how to add paths was a Godsend!

  • @12Q46HPRN
    @12Q46HPRN 2 ปีที่แล้ว +9

    Great video! Thanks for the education.
    Like a script-kiddie, I was just copy/pasting the line: PATH="$HOME/Applications:$PATH" (changing "Applications" to whatever I needed to add) without fully understanding the simple syntax. Now I do. This means worlds to me!
    I also agree that a playlist of these UNIX/Linux/POSIX commands would be great to help find them all.

  • @VeslorTV
    @VeslorTV 2 ปีที่แล้ว +4

    Awesome content DT cheers from Spain

  • @supersoniqamanyi3075
    @supersoniqamanyi3075 ปีที่แล้ว

    Title should be “Environment Variable for 8years olds…” it’s actually that CLEAR !!! Thanks, man.

  • @rafiahmed5017
    @rafiahmed5017 2 ปีที่แล้ว +1

    Thank u. I thought installing arch would be really hard ; but your previous tutorial videos had really taught me a lot about that

  • @owendavidmalicsi5900
    @owendavidmalicsi5900 2 ปีที่แล้ว +1

    Wow DT. Your lighting is getting better and better

  • @theamithsingh
    @theamithsingh ปีที่แล้ว

    love the explaination, why can't people keep videos nice and simple like this.

  • @Paul_I_S
    @Paul_I_S 2 ปีที่แล้ว +1

    Thx. for doing great job on this channel. Currently I'm migrating back to Linux. Currently I'm struggeling to set up my printer (ET-3750). But I guess it's just a matter of setting the right permissions or the right environment variables.....
    Your channel is doing a great job bringing me back up to speed!

  • @nnywadd
    @nnywadd 2 ปีที่แล้ว +3

    You're looking lean bro. Great video.

  • @ikillyou96
    @ikillyou96 2 ปีที่แล้ว +15

    Great video, btw 32767 is the highest number that can be represented in a signed 16-bit integer.

    • @ENTMusic-cj7wt
      @ENTMusic-cj7wt 2 ปีที่แล้ว

      Wait, it is from 0 to 32767, so wouldn't it be an unsigned int then?

    • @ikillyou96
      @ikillyou96 2 ปีที่แล้ว +6

      @@ENTMusic-cj7wt No, unsigned 16 bit int would be up to 65535. But due to the use of two's complement, we get half the positive range and no negative numbers :)

  • @call_me_Lloydy
    @call_me_Lloydy 2 ปีที่แล้ว

    I keep on learning 😊

  • @RishiR
    @RishiR 2 ปีที่แล้ว +1

    THANK YOU!

  • @gabrielbap1
    @gabrielbap1 2 ปีที่แล้ว

    Great video

  • @anikbiswasarnob
    @anikbiswasarnob 2 ปีที่แล้ว +1

    Wow! your T-Shirt is so awesome 😃

  • @Somabilbooks
    @Somabilbooks ปีที่แล้ว

    thank you Very Much

  • @vintovkasnipera
    @vintovkasnipera 2 ปีที่แล้ว +2

    Just the video I was looking for! Thanks

  • @dwillingham
    @dwillingham 2 ปีที่แล้ว +1

    Thanks!

  • @parthachattopadhyay2181
    @parthachattopadhyay2181 2 ปีที่แล้ว

    Hey DT, the range 32767 is int with size 2 (byte). So for a variable defined with integer size 2 can store -32768 to 32767. Thanks for the videos.

  • @mightGalaxyBlackhole
    @mightGalaxyBlackhole ปีที่แล้ว

    You are very good and decently detailed with you presentations. How many years will it take a newbie to get to your level?

  • @PrashantSharma-ql4yb
    @PrashantSharma-ql4yb 2 ปีที่แล้ว +1

    love the T-Shirt

  • @shubham_srt
    @shubham_srt 2 ปีที่แล้ว

    thank youuuu

  • @socvirnylestela5878
    @socvirnylestela5878 2 ปีที่แล้ว

    btw have u tried river? a tiling window manager for wayland?

  • @thalhas9760
    @thalhas9760 2 ปีที่แล้ว

    Thanks

  • @xarisfil58
    @xarisfil58 2 ปีที่แล้ว

    do you have any dotfiles for the specific qtile or something else I think window manger setup?

  • @AndersJackson
    @AndersJackson 2 ปีที่แล้ว +5

    Actually, Environment variables are defined in the process that run any program, not just Shells.
    And in Bash, and other Shells, there are variables in the Shell (Bash has both local and global variables in the Shell).
    Environment variables are the ones in the process.
    The Good thing is that Environment variables are copyed to the child process. Then the parent process can't change them for the child process.
    And No process can change any other process Environment variables. Not even the patents.
    MS Dos have global Environment variables, so any process can change any other programs Environment variables. Which is bad.

    • @killistan
      @killistan 2 ปีที่แล้ว

      Isn't Dos basically single process though? I'd think that that would mitigate that problem pretty well... Unless future scripts don't initialize their variables properly.

    • @Jupiter__001_
      @Jupiter__001_ 2 ปีที่แล้ว

      So DOS runs into a similar problem as if one were to attempt to use EMACS as an OS?

  • @CyberDwarf1949
    @CyberDwarf1949 2 ปีที่แล้ว

    Niceee!
    👏👏👏

  • @GuyWhoChad
    @GuyWhoChad 2 ปีที่แล้ว

    hey dt!, i have a question, how can i make the dtos installer?, like when you launch dtos installer it is a GUI INSIDE TERMINAL LIKE NCURSES HOW CAN I DO THAT?

  • @edbeckerich3737
    @edbeckerich3737 2 ปีที่แล้ว +3

    I need this info in a cheat sheet, i forget it everytime i need it, as long as its in Bash, it never changes

    • @TrueDetectivePikachu
      @TrueDetectivePikachu 2 ปีที่แล้ว +2

      @@fedup6127 or markdown, it's less verbose than html

    • @Gabifuertes
      @Gabifuertes 2 ปีที่แล้ว

      @@TrueDetectivePikachu markdown is great for this purpose, and if you need it as html there's pandoc

  • @user-si2vn2si5c
    @user-si2vn2si5c หลายเดือนก่อน

    Cool T-shirt man, where buy??

  • @milutinke
    @milutinke 2 ปีที่แล้ว +10

    Hey DT!
    Can you make a playlist with ordered tutorials for absolute beginners at GNU/Linux?
    A playlist that would include an explanation about what is GNU/Linux, how it came to be, what is POSIX compliance, how it differs from other Unix-like systems, then the basics about the OS, basics of the bash shell, why FOSS matters, etc.
    You already have made a lot of videos about those topics, so you could make shorter versions, in which you could link to longer versions, or just link the existing ones in order. (Shorter because people these days have attention span on the level of a goldfish)
    A lot of people I know want to switch to GNU/Linux because now Proton supports GNU/Linux gaming, it would be neat to point them to a propper source where they would get proper and good knowledge about GNU/Linux and FOSS, instead of not knowing much and being sheep who distro hop because they do not know how to properly configure things, or think the wrong things about GNU/Linux.

    • @xrafter
      @xrafter 2 ปีที่แล้ว +1

      How dare you insult me with that " people these days have attention span of goldfish"
      Please say sorry

    • @anantgupta1188
      @anantgupta1188 2 ปีที่แล้ว

      I have can have a small attention span like a goldfish but when I am @Linux it can be as long as 3-4 hours

  • @007arek
    @007arek 2 ปีที่แล้ว

    Why if I put my envs in zprofile or zshenv system doesn't see they? For example sxhkd can't use it.

  • @AcidiFy574
    @AcidiFy574 2 ปีที่แล้ว +3

    How about videos about making POSIX compliant Scripts or POSIX compliance in general???

    • @Aleksandar0100
      @Aleksandar0100 2 ปีที่แล้ว

      shellcheck

    • @zvezdan956
      @zvezdan956 2 ปีที่แล้ว

      he uses fish

    • @AcidiFy574
      @AcidiFy574 2 ปีที่แล้ว

      @@zvezdan956 It's worth a shot

  • @elys7563
    @elys7563 2 ปีที่แล้ว

    Hey dt, have you heard of ‘darling’(it’s like wine for Macos)... Btw very informational video

  • @longhoacaophuc8293
    @longhoacaophuc8293 2 ปีที่แล้ว +1

    Hey DT, how do you colourize your ls command?

    • @HontoNeet
      @HontoNeet 2 ปีที่แล้ว +2

      I believe his “ls” is actually an alias for the program “exa” which is an alternative to ls with more features

    • @le0nz
      @le0nz 2 ปีที่แล้ว +1

      Yup dt uses exa and the set ls as an aliaz

    • @longhoacaophuc8293
      @longhoacaophuc8293 2 ปีที่แล้ว

      @@HontoNeet oh, thanks for the information!

  • @Spiritualitydefined
    @Spiritualitydefined 2 ปีที่แล้ว

    shell-color-scripts: local (1.0.r52.3dbdfac-1) is newer than AUR (1.0.r39.143937f-1) getting this how do you fix it?

    • @theodiscusgaming3909
      @theodiscusgaming3909 2 ปีที่แล้ว

      read the error. It looks like the version you have is newer than the one available in the AUR for some reason, so just wait.

  • @Paul_I_S
    @Paul_I_S 2 ปีที่แล้ว

    👍

  • @boblol1465
    @boblol1465 2 ปีที่แล้ว

    do a video on hannah montana linux

  • @itdepends604
    @itdepends604 2 ปีที่แล้ว

    can someone explain the difference between ~ and $HOME. When should you use one over the other?

    • @itdepends604
      @itdepends604 2 ปีที่แล้ว

      @Obvious Honeypot what shell doesn't support ~?

    • @theodiscusgaming3909
      @theodiscusgaming3909 2 ปีที่แล้ว

      use $HOME in scripts for better compatibility, and ~ in commands.

  • @dhrubajitchakravarty54
    @dhrubajitchakravarty54 2 ปีที่แล้ว

    Sir when is DTOS coming sir pls reply waiting for it eagerly

    • @SimGunther
      @SimGunther 2 ปีที่แล้ว

      When it's ready

    • @peenywallie
      @peenywallie 2 ปีที่แล้ว

      Why do Indians always say "sir"?

    • @Jupiter__001_
      @Jupiter__001_ 2 ปีที่แล้ว

      @@peenywallie I suppose it must be good etiquette in their languages.

  • @PhilipHarwell
    @PhilipHarwell 2 ปีที่แล้ว +1

    Surprised it isn’t uid == 0, typically in programming, you need two = for equality check. Single = is for assigning value to a variable.

    • @xrafter
      @xrafter 2 ปีที่แล้ว +1

      You can use == with the shell built-in that starts with [[ and end with ]]>

    • @stephan6530
      @stephan6530 2 ปีที่แล้ว +2

      Bash accepts both '==' and '=' for string equality comparison. '=' is usually used with the 'test' command for POSIX conformance.

  • @kapellimestari0078
    @kapellimestari0078 2 ปีที่แล้ว

    Hello, i just watched you video about irssi, and do you know some chat program like this one? but safety and privacy... Or batter, maybe could you teach how create a chat between two computer? wait, a better topic, if you know could you please make a video about cryptography, and the asymmetric cryptography, and the most important, how to apply the asymmetric, because for example , I know about it, but I don't really know how to use it, how to implement and so on and so forth. Or maybe anyone who is reading this comment could please send me a video or a site or a book about it please

  • @aer0449
    @aer0449 2 ปีที่แล้ว +1

    That print on his T-shirt is of religious Goddess in Hinduism...

  • @Tn5421Me
    @Tn5421Me 2 ปีที่แล้ว

    I just realized you have /home/dt/.local/bin in your path twice

  • @chiranjeevinaidu3660
    @chiranjeevinaidu3660 2 ปีที่แล้ว +1

    Bro can you make a video on how we can setup our own cross platform terminal that can run all the commands of bash and cmd it will be really cool if you could make a video on this topic.

  • @sourabhk2373
    @sourabhk2373 2 ปีที่แล้ว +1

    What is a Hindu Goddess doing on your t-shirt ?
    PS: Nice video!

  • @tomoghnosen
    @tomoghnosen 2 ปีที่แล้ว +2

    Is it goddess Kali maa in your tshirt

  • @punishr90
    @punishr90 2 ปีที่แล้ว

    Thats a 'KALI' on his t-shirt

  • @kerodfresenbetgebremedhin1881
    @kerodfresenbetgebremedhin1881 2 ปีที่แล้ว

    it is 32767 because it uses 16 bits to store

  • @MaxHeroGamer
    @MaxHeroGamer 2 ปีที่แล้ว

    32767 is the maximum number you can represent with 15 bits. I don't know why they used 15 bits for it, though.

    • @hughesd.mungus9819
      @hughesd.mungus9819 2 ปีที่แล้ว +1

      it's the max of a signed 16 bit number so -32768 to 32767

    • @MaxHeroGamer
      @MaxHeroGamer 2 ปีที่แล้ว

      @@hughesd.mungus9819 Oh it's signed...

  • @billfarley9015
    @billfarley9015 2 ปีที่แล้ว

    I don't have mouseface. not in repo. I found it in Github. Can someone please tell me the command to download it. The Github-clueless among us would appreciate it. I do have fortune though. The first time I tried it I got this : Q: How many existentialists does it take to screw in a light bulb? A: Two. One to screw it in and one to observe how the light bulb itself symbolizes a single incandescent beacon of reality in a netherworld of endless absurdity reaching out to a maudlin cosmos of nothingness.

  • @plasmalife5532
    @plasmalife5532 2 ปีที่แล้ว

    Difference between $HOME AND ~/ ??

    • @xrafter
      @xrafter 2 ปีที่แล้ว

      same thing in the man page of ls or something idr, "~" is almost always $HOME .

    • @killistan
      @killistan 2 ปีที่แล้ว +2

      do this in a shell to get a behavioral idea:
      echo ~
      echo "~"
      echo $HOME
      echo "$HOME"
      basically, $HOME is a variable, ~ is something more like a glob (It's not technically a glob). You'll notice that when quoted, the variable is expanded, but ~ is not.

    • @xrafter
      @xrafter 2 ปีที่แล้ว +1

      @@killistan
      Wow i just try it and it blew my mind .
      ~ is rigged .

    • @killistan
      @killistan 2 ปีที่แล้ว +1

      @@xrafter Yeah, almost always use $HOME in scripts, but who wants to type that in the command line all the time?

    • @plasmalife5532
      @plasmalife5532 2 ปีที่แล้ว

      Thanks to everyone

  • @praetorxyn
    @praetorxyn 2 ปีที่แล้ว

    It's a pity there's not a good "shell agnostic" way of setting global environment variables for things like XDG compliance... at least not when you include the fish shell in the criteria for "shell agnostic." I know you could edit .profile or /etc/profile or something... but the whole point of forcing XDG compliance is to get rid of things like .profile.
    I suppose you could set the default shell to bash and just have bash set the variables and launch fish, and I think the variables might persist to the fish session and your desktop environment... but eh. Such a hack.

    • @AndersJackson
      @AndersJackson 2 ปีที่แล้ว

      No, XGD are not about remove /etc/profile etc.
      It is about being able to use locale adjusted directories, like ~/Document is used in English locale and ~/Dukument in Swedish. And config files in ~/.config etc.
      Has nothing to do with Shell init files. You still need Them
      That is what the environmen

    • @praetorxyn
      @praetorxyn 2 ปีที่แล้ว

      @@AndersJackson I never said it was supposed to get rid of anything in /etc... but /etc is beyond the scope of user configuration, so changes there can't easily be stored in a dotfiles repo.
      You literally just said XDG is so that user configuration goes in ~/.config. ~/.profile, ~/.vim, ~/.ssh, etc literally all violate this. It should be ~/.config/profile, ~/.config/vim, ~/.config/ssh, etc.
      fish is the only shell that respects XDG (though you can sort of force zsh to do so by setting ZPROFILE early enough... though you'd probably need to face the same sort of conundrum to do so.

  • @neuzen
    @neuzen 2 ปีที่แล้ว

    BTW I use fish

  • @send2gl
    @send2gl 2 ปีที่แล้ว

    Why would someone use a sub shell?

    • @Gabifuertes
      @Gabifuertes 2 ปีที่แล้ว +1

      Try fish and you'll be invoking bash for opening scripts or just out of frustration

    • @send2gl
      @send2gl 2 ปีที่แล้ว

      @@Gabifuertes I can understand an alternative terminal but can't quite get why someone would use a terminal to open another terminal. Unless of course there are circumstances (of which I am not aware) whereby one terminal is preferable to another.

  • @arkvsi8142
    @arkvsi8142 2 ปีที่แล้ว +1

    I use MS DOS

  • @williemaddox9919
    @williemaddox9919 2 ปีที่แล้ว

    You have an extra /home/dt/.local/bin in your $PATH just fyi...

  • @bahathir_
    @bahathir_ 2 ปีที่แล้ว

    $ p='Hello. '
    $ echo $p
    Hello,
    $ p+='world!'
    $echo $p
    Hello, world!

  • @leviticus8930
    @leviticus8930 2 ปีที่แล้ว +3

    First?

  • @Waffelo
    @Waffelo 2 ปีที่แล้ว +1

    Waffelo

  • @ignisimmensus2568
    @ignisimmensus2568 2 ปีที่แล้ว

    Can you please use timestamps on your videos? thanks

  • @plasmalife5532
    @plasmalife5532 2 ปีที่แล้ว +2

    Are you supporting hindu religion 🤔 (t-shirts)

    • @vintovkasnipera
      @vintovkasnipera 2 ปีที่แล้ว

      doesn't necessarily mean so

    • @anantgupta1188
      @anantgupta1188 2 ปีที่แล้ว +2

      not sure but in one video he says that he read holy books of many religions like the bible, Quran, Bhagavad Gita
      If anyone notices that he also have lord buddha statute

  • @dkosmari
    @dkosmari 2 ปีที่แล้ว +2

    I'm gonna try to offer some constructive criticism, since I feel like this was of lower quality than, say, your org-mode videos.
    One mistake you're making here is trying to reword and rename concepts, to the point of being technically wrong.
    For instance, your usage of "local" vs "global" variables doesn't match what is actually local vs global variables in shell scripting. You meant "variables" vs "environment variables", because that's what Bash (and POSIX) names them.
    Questions that I think should have been answered in the video:
    - What is a variable?
    - What is the environment?
    - How do you add, change or remove a variable in the environment?
    - How do you modify the environment only for the child process?
    - What are the standard ways to persistently customize the environment?
    That last one is the single most useful information for people that don't want to dive into shell programming, yet you devoted the least amount of time to it.
    - "Why does my PATH have the same location twice?"
    - "Why does my shell see the variable, but the script I invoke doesn't?"
    - "Why isn't ~/.config/environment.d working is the documentation says it should work?" (Spoiler: because systemd.)

  • @MrTAL69
    @MrTAL69 2 ปีที่แล้ว +1

    Sorry DT but there are actual definitions for concepts of local and global variable, and that's not it. Since you're being (for a good reason!) followed by total newbies, you really shouldn't be playing it fast and loose. Oher people may at a later point need to un-teach incorrect concepts before they can learn correct ones; and that's a bi*ch job.

  • @aaronspeedy7780
    @aaronspeedy7780 ปีที่แล้ว

    11:02 You can just do $PATH+=:/path_to_dir

  • @mikael5743
    @mikael5743 2 ปีที่แล้ว

    Thanks