Logo video2dn
  • Сохранить видео с ютуба
  • Категории
    • Музыка
    • Кино и Анимация
    • Автомобили
    • Животные
    • Спорт
    • Путешествия
    • Игры
    • Люди и Блоги
    • Юмор
    • Развлечения
    • Новости и Политика
    • Howto и Стиль
    • Diy своими руками
    • Образование
    • Наука и Технологии
    • Некоммерческие Организации
  • О сайте

Скачать или смотреть How to Set Environment Variables from a Shell Script

  • vlogize
  • 2025-09-26
  • 0
How to Set Environment Variables from a Shell Script
How to set enviroment variable from shell scriptshellenvironment variables
  • ok logo

Скачать How to Set Environment Variables from a Shell Script бесплатно в качестве 4к (2к / 1080p)

У нас вы можете скачать бесплатно How to Set Environment Variables from a Shell Script или посмотреть видео с ютуба в максимальном доступном качестве.

Для скачивания выберите вариант из формы ниже:

  • Информация по загрузке:

Cкачать музыку How to Set Environment Variables from a Shell Script бесплатно в формате MP3:

Если иконки загрузки не отобразились, ПОЖАЛУЙСТА, НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если у вас возникли трудности с загрузкой, пожалуйста, свяжитесь с нами по контактам, указанным в нижней части страницы.
Спасибо за использование сервиса video2dn.com

Описание к видео How to Set Environment Variables from a Shell Script

Learn how to effectively set environment variables using shell scripts and ensure they persist in your current terminal session.
---
This video is based on the question https://stackoverflow.com/q/63016867/ asked by the user 'Alexandr Zhukov' ( https://stackoverflow.com/u/13818254/ ) and on the answer https://stackoverflow.com/a/63018029/ provided by the user 'Paul Hodges' ( https://stackoverflow.com/u/8656552/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions.

Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: How to set enviroment variable from shell script

Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l...
The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license.

If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com.
---
How to Set Environment Variables from a Shell Script

Setting environment variables in a Unix-like operating system can sometimes be tricky, especially when using shell scripts. You might encounter issues where the environment variables you set within a script don’t seem to apply in your current terminal session. In this post, we’ll explore this problem and provide a step-by-step solution to ensure your environment variables are correctly set.

The Problem

Imagine you have a shell script named set_env.sh, which is intended to export an environment variable. Its contents might look something like this:

[[See Video to Reveal this Text or Code Snippet]]

When you run this script from the terminal using:

[[See Video to Reveal this Text or Code Snippet]]

you find that the expected environment variable LD_LIBRARY_PATH is not set. In fact, running the following command:

[[See Video to Reveal this Text or Code Snippet]]

returns nothing. This can be perplexing, but understanding how shell processes work will clarify why this happens.

Understanding Shell Processes

When you execute a script (like set_env.sh) with ./set_env.sh, you are running it in a child process. This child process executes the commands in the script, but when it finishes, it discards all changes made to the environment variables. Consequently, the parent process (your current terminal session) remains unaffected.

Key Points:

A child process cannot modify the environment of its parent process.

Once the child process terminates, any changes it made to environment variables are lost.

The Solution

To effectively set environment variables using your shell script so they persist in the current terminal session, you need to use a method that allows the script to directly modify the current shell environment.

Use the source Command

Instead of executing the script in a new shell instance, you should source it. This reads and executes the content of the script in the context of the current shell session.

You can do this in two ways:

Using the source command:

[[See Video to Reveal this Text or Code Snippet]]

Using a dot (.) which is a shorthand for source:

[[See Video to Reveal this Text or Code Snippet]]

What Happens When You Source a Script

When you source a script:

The commands in the script are executed in the current shell.

Any environment variables exported will remain in the current shell session.

Conclusion

Setting environment variables from within shell scripts requires an understanding of how processes work in the shell. By recognizing that a child process cannot alter the parent's environment, you can effectively use the source command to ensure that your variables persist in your terminal.

Now, the next time you need to set environment variables from a script, remember to source it rather than executing it directly. Happy scripting!

Комментарии

Информация по комментариям в разработке

Похожие видео

  • О нас
  • Контакты
  • Отказ от ответственности - Disclaimer
  • Условия использования сайта - TOS
  • Политика конфиденциальности

video2dn Copyright © 2023 - 2025

Контакты для правообладателей [email protected]