首页 > 其他分享 >[Bash] Environment variables

[Bash] Environment variables

时间:2024-06-10 14:43:56浏览次数:18  
标签:lib variables substack Environment usr home declare Bash

Environment variables are defined by the shell and shell scripts.

To list the current environment variables, type export:

~ $ export
declare -x DISPLAY=":0"
declare -x HOME="/home/substack"
declare -x HUSHLOGIN="FALSE"
declare -x LANG="en_US.UTF-8"
declare -x LD_LIBRARY_PATH="/home/substack/prefix/lib:/usr/local/lib:/usr/lib/x86_64-linux-gnu:/usr/lib:/lib64:/lib"
declare -x LIBGL_DRIVERS_PATH="/usr/lib/i386-linux-gnu/dri:/usr/lib/x86_64-linux-gnu/dri"
declare -x LOGNAME="substack"
declare -x MAIL="/var/mail/substack"
declare -x OLDPWD="/home/substack/projects/workshops"
declare -x PATH="/home/substack/prefix/bin:/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin:/usr/local/games:/usr/games"
declare -x PREFIX="/home/substack/prefix"
declare -x PWD="/home/substack"
declare -x ROXTERM_ID="0x43962f0"
declare -x ROXTERM_NUM="15"
declare -x ROXTERM_PID="2521"
declare -x SHELL="/bin/bash"
declare -x SHLVL="3"
declare -x TERM="xterm"
declare -x USER="substack"
declare -x WINDOWID="8684328"
declare -x WINDOWPATH="7"
declare -x XAUTHORITY="/home/substack/.Xauthority"

You can use any environment variable by refering to its $NAME.

For example to print the value of $HOME do:

~ $ echo $HOME
/home/substack

You can use environment variables in any command:

~ $ ls /home/$USER
doc  media  notes.txt  projects

To define your own environment variable, just put its name followed by an equal sign (with no spaces) followed by its value:

~ $ ANIMAL=cats
~ $ echo $ANIMAL
cats

Define env variables like this only exists for the current bash session, if you open a child node process, env variable won't be there.

If you want it to be avaiable for child process, you can use export

~ $ export ANIMAL=cats
~ $ node
~ $ process.env.ANIMAL
~ $ cat

标签:lib,variables,substack,Environment,usr,home,declare,Bash
From: https://www.cnblogs.com/Answer1215/p/18240657

相关文章

  • Go - Using error variables to differentiate between input types
     packagemainimport("fmt""os""strconv")funcmain(){arguments:=os.Argsiflen(arguments)==1{fmt.Println("Notenougharguments")}vartotal,nInts,nFloatsint......
  • 在Linux中,什么是 BASH?
    在Linux中,BASH(BourneAgainSHell)是一个广泛使用的shell,也是大多数Linux发行版的默认shell。BASH是Bourneshell(sh)的一个替代品,由BrianFox和ChetRamey编写,以改进sh的功能和易用性。以下是关于BASH的详细解释:1.定义BASH是一个命令行解释器(也称为shell),它允许用户与操作系统进行......
  • [Bash] Backticks, xargs and Arithmetic
    BackticksUsingtoexeccmdandreturntheoutputasstring$echo`date`FriJun715:40:11EEST2024Thesameeffectyoucanachievebyusing$echo$(date)FriJun715:40:11EEST2024Examples$echo`date+%F`2024-06-07$echosomelogdata>......
  • 如何用在bash中截取部分系统参数?
    背景在编程过程中遇到一个问题。在一个bash脚本中,我需要用lame重新生成音频文件的压缩版本。原有的参数为三个:种子值、源txt文件和目标wav文件。我希望的是能够顺便自动生成压缩的mp3版本以及添加了背景音乐的版本,但是我又不希望添加新的输入参数。这样,对于原本的系统参数进行切......
  • 在Linux中,BASH 和 DOS之间的区别是什么?
    BASH(BourneAgainSHell)和DOS(DiskOperatingSystem)之间存在显著的区别,这些差异不仅体现在它们的设计哲学、功能特性上,也反映在它们所服务的操作系统环境及其用途上。以下是一些主要的区别:性质和定位:BASH:是一种命令行解释器(shell),它是用户与Linux或其他类UNIX操作系统交互......
  • bash实现当前路径下子目录跳转
    说明很早之前尝试过autojump项目,当时使用bash函数实现jc功能,最低测试过Ubuntu16.04日常中高频使用,今天使用添加了bash补全,分享给诸位配置function_j_completion(){localcur=${COMP_WORDS[COMP_CWORD]} COMPREPLY=($(compgen-W"$(echo-n$PWD|sed's/\///g')"-......
  • Environment类使用
    Environment.getProperty是Spring框架中的一个方法,它属于org.springframework.core.env.Environment接口。这个方法主要用于从应用程序的运行环境中读取配置属性值。当你需要在代码中动态获取配置文件(如application.properties或application.yml)中的某个属性时,getProperty就非常......
  • [Bash] pbcopy command
    pbcopyisacommand-lineutilityavailableonmacOSthatallowsyoutocopytheoutputofacommanddirectlytotheclipboard.Itcanbeveryhandyforquicklycopyingtextortheresultsofcommandstouseelsewhere.#CopyTexttoClipboard:echo"......
  • 【Azure Developer】Python – Get Access Token by Azure Identity in China Azure E
    问题描述使用AzureIdentity,根据指定的客户端凭据获取AccessToken中,先后遇见了“ValueError:"get_token"requiresatleastonescope”“ClientSecretCredential.get_tokenfailed:Authenticationfailed:sequenceitem0:expectedstrinstance,listfound”最初的......
  • error: no configuration has been provided, try setting KUBERNETES_MASTER environ
    1:问题kubernetes集群,一台master,一台node1,一台node2,重启电脑后,node1节点和node2节点报错如下error:noconfigurationhasbeenprovided,trysettingKUBERNETES_MASTERenvironmentvariable2:解决方法2.1:查看master节点进入到该目录下cd/etc/kubernetes把admi......