All Questions
Tagged with bash environment-variables
209
questions
0
votes
1
answer
2k
views
Where to set env var for Debian12?
There are too many places can hold permanent env var settings in Linux, so that I can't finger out which one is the most correct/proper.
/etc/environments
/etc/bash.bashrc
/etc/profile
/etc/profile.d/...
-1
votes
1
answer
415
views
Set Variable to ls command output
I'd like to create a variable from the output of a bash command. How does one create a variable out of the output of the command "ls /Users".
Variable creation does not work in this case:
...
1
vote
1
answer
65
views
Bash terminals launched from windows UI have an invalid `!::=::\` variable set
When I run printenv one of the returned variables is !::=::\. I noticed that the variable exists because docker does not work correctly with it set.
$ printenv | grep ::
!::=::\
$ docker stack deploy ...
1
vote
1
answer
548
views
Expand variable to alias and execute
I have an alias set in my .bash_aliases file to execute neovim.
I can successfully use this alias from the command line however I cannot use this alias via a variable (ie the EDITOR variable - set in ....
0
votes
1
answer
1k
views
How to start tmux session that overrides environment variables set in .bash_profile?
Suppose I have an environment variable set inside .bash_profile: export ABC=from_bash_profile.
$ echo $ABC
from_bash_profile
When I try to create a new tmux session with environment variables for ...
0
votes
1
answer
877
views
Securing username and password passed as Environment variable
Username and Password are passed as plain text as environment variable while running a bash script from a existing process. using following command.
sudo -u someuser USERNAME=abc PASSWORD=xyz /path/to/...
1
vote
0
answers
458
views
Environment Variable not showing up
I am implementing public private key based authentication and I need to parameters the location where I store my keys. So that, programmatically my jobs can read it from this location and establish ...
0
votes
2
answers
4k
views
Setting environment variables in bash script doesn't work?
If I run this on the command line, it will make the commit be at the specified date:
THE_TIME='2022-01-01T22:50:12 -0700' GIT_AUTHOR_DATE=$THE_TIME GIT_COMMITTER_DATE=$THE_TIME git commit -am 'commit'
...
0
votes
0
answers
1k
views
How to copy file of env variable to another file
I am executing bash commands inside a yaml file. I have set an env variable SECRET which point to a yaml file in my home directory, and I want to copy the content of this yaml file to another file, as ...
0
votes
2
answers
1k
views
Setting environment variables using eval - by calling other shell script
I have two shell scripts Caller and getGlobalParameters.
There is a function defined in the getGlobalParameters script which calls a java class and uses the values returned by the java class to set ...
1
vote
1
answer
58
views
How to add environment variables to "mdkir -p" bash command?
Lets say I have an environment variable var="html,xhtml". I want to create a directory with subfolders, like so:
mkdir -p Website/{static/{cs,js},templates/{html,xhtml}}
How can I replace {...
0
votes
1
answer
6k
views
Load ENV file from bash script
I have a bash script that has the following content :
#!/bin/bash
source ./django.dev.env
docker compose --env-file ./uvicorn.dev.env -f ./docker-compose.yaml
and a django.dev.env file with the ...
0
votes
2
answers
501
views
How to find where the variable come from in a bash set command?
It happens I have some unwanted environment variable inside the set command output, and I can't get rid of these:
$ set
ALL_PROXY=socks://127.0.0.1:10010/
.... (lots of environment variables)
...
1
vote
3
answers
1k
views
BASH Loop Through Variables
If i have a bunch of variables in bash, like this:
foo_1="path/1"
foo_2="path/2"
foo_3="path/3"
foo_4="path/4"
foo_5="path/5"
They all start with ...
6
votes
2
answers
6k
views
Assign result of conditional expression to environment variable
I'd like to store the result of a conditional expression in an environment variable.
I tried:
C=$([ "$A" = "$B" ])
but the value of $C after running that is an empty string.
I ...
2
votes
1
answer
867
views
Bash or zsh conditional patterns and variable expansions
Suppose I want to generate a filename based on some given variables.
track=01
title="Some title"
album="Some album"
echo ${track}. ${title} (${album})
-> 01. Some title (Some ...
0
votes
0
answers
78
views
Variables inside commands inside if statement
I do not understand why this does not work:
existing_user=$(ldapsearch -x -b "cn=group,ou=group2,dc=company,dc=com" -H ldap://127.0.0.1 -D "cn=admin,dc=company,dc=com" -w "...
0
votes
1
answer
1k
views
$PATH editting does not work
I am using Ubuntu 64-bit on a VM and installed an app, added it to $PATH using export PATH=$PWD/bin:$PATH in my terminal (T1). Worked fine. Then i wanted to use the command in another terminal (T2) ...
1
vote
2
answers
785
views
SHELL environment variable keeps returning the value of default shell
I'm using a terminal emulator with bash as the default shell ,then printed the value of the environment variable SHELL to print the current shell and it did , but when i enter another shell i.e., ...
6
votes
1
answer
17k
views
How to add a path to PATH variable in linux alpine for the entire machine?
I know I can export PATH="$PATH:my_path" to add to PATH variable in current session.
I also know that I can add this line to ~/.bash_profile to make it persist across sessions for my user:
...
1
vote
1
answer
143
views
Modify .bashrc variable from a loop from shell
So I created this loop in ~/.bashrc:
export test_var1=TRUE
for (( a=0;a<1;a )); do
if [[ $test_var1 == "TRUE" ]]; then
sleep 1
echo "teststuff happening! test_var1=${...
0
votes
1
answer
997
views
Why giving an environment variable to sudo su fails?
Putting PATH variable into sudo su - USER occurs an error:
USER1@SERVER:~:$ sudo PATH=$PATH su - USER2
sudo: sorry, you are not allowed to set the following environment variables: PATH
Following the ...
3
votes
2
answers
6k
views
sudo: sorry, you are not allowed to set the following environment variables
I set an alias for sudo as:
alias sudo='sudo PATH=$MY_PATH'
I checked that this works well by running sudo printenv PATH.
However, I encounter an error when running sudo su - USER2.
sudo: sorry, you ...
0
votes
1
answer
2k
views
SHELL="/bin/bash" vs SHELL="bash"
What's the difference between exporting SHELL="/bin/bash" and SHELL="bash"? I previously had export SHELL="bash" in my .bashrc. It seemed to work. $($SHELL) spawned a ...
0
votes
1
answer
716
views
Sed special characters in variable '&'
Sorry, easy question, but I can't find how to do it: I have a special char "&" in a Variables that I have to use in sed.
Example:
#The template .env
cat .env
MY_SECRET = VAR_MY_SECRET
...
1
vote
1
answer
450
views
environment variable in scripts with heredoc
script: t1.sh
DEST=`mktemp -d`
echo "DEST=$DEST"
script: t2.sh
sudo -s <<EOF
DEST=`mktemp -d`
echo "DEST=$DEST"
EOF
invoking t1.sh, with or without sudo:
$ bash t1.sh
DEST=/...
1
vote
1
answer
7k
views
How do I set environment variable by importing from a file?
I know set command sets environment variables temporarily while set command sets environment variables permanently.
This command exports current environment variable path to a file
echo %path% > ...
0
votes
1
answer
378
views
`wsl env` gives different result to `wsl` followed by `env`
Inside WSL (i.e. by opening a cmd and then running wsl, or just running wsl straight from the start menu) I have this line at the end of ~/.bashrc:
LANG=en_US.UTF-8
While still inside WSL, if I do ...
10
votes
2
answers
2k
views
Can a process run regardless of any shell?
I'm trying to grasp the concepts of shell and terminal and the exact relation between them from the aspect of OS processes. So I have few questions in that field.
Sanity check: As far as I understand,...
0
votes
1
answer
586
views
my terminal is not recognizing my flask command after i installed flask
I ran into a problem with the terminal, it didn't recognize my flask command!
the whole issue started with
WARNING: The script isort is installed in '/Users/bigdad/Library/Python/3.8/bin' which is not ...
2
votes
1
answer
1k
views
concatening a variable to a file using cat
I wanted to do a bash function that given a text variable, it would concatenate it to a file. i.e
function print() {
cat << 'EOF' >> file
This $1 is a variable
EOF
}
But it wouldnt work. ...
0
votes
0
answers
45
views
Built in terminal extensions showing different files than default bash terminal
I'm attempting to use a Sublime Text 3 extension Terminus, on Clear Linux, but am having a strange issue I did not run into on Ubuntu 20 - the same issue applied to the other similarly functioning ...
0
votes
2
answers
962
views
Change home directory
I'm trying to access a folder with a bunch of files via cd $HOME_KADATH however I'm thrown into my 'normal' home directory. Is there anyway to change the home directory to the one above instead?
This ...
1
vote
1
answer
511
views
Setting Environment variable for bash/zsh completion
I am using gnu pass with bash/zsh completion. This means when I type pass a[TAB] the shell suggests which passwords I have available starting with a.
I have two gnu-pass directories, when I want to ...
2
votes
1
answer
3k
views
Is there a way to query WSL environmental variables from within Windows / Command prompt?
On my quest to make my WSL Windows Toolbar Launcher working, I found out that my attempt to set environmental variables for WSL from within command prompt futile:
Within command prompt, I can do a wsl ...
0
votes
0
answers
23
views
Setting many variables written in a file to set in the environment of Shell at a time?
I have written many variables to be set as environement variables in a file , how should i set them all at a time .
Sample Code in File :
BRUN_ABORT_DEPENDENT_JOBS_ON_NONZERO_EXIT="true"; export ...
0
votes
1
answer
783
views
Adding executable files to my PATH in a Linux shell
My goal is to run the R file helloworld.r from my home directory using Rscript in a Linux shell. My helloworld.r file looks like this
#!/home/usr/env Rscript
print("Hello World")
I have added export ...
0
votes
1
answer
47
views
Can systemctl return an empty code?
Consider the following setting:
systemctl is-active --quiet $SERVICE_NAME
STATUS=$?
Can it happen under any circumstances that $STATUS is then not set or empty? That is, because systemctl returns no ...
1
vote
0
answers
132
views
How do I ensure bash *never* expands paths in environment variables when tab-completing?
$ bash --version
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
I normally using the above bash version on an Ubuntu 16.04 machine via MATE terminal. Currently however I am using macOS 10....
0
votes
1
answer
1k
views
How to pass whole environment from target Linux to client Linux over one ssh session?
I have script on target Linux (RedHat, PC_A) which I would like to execute from source Linux (RedHat, PC_B) during remote login session.
I'm trying to execute following command :
[user2@PC_B] ssh &...
0
votes
1
answer
6k
views
Why I can't permanently remove these environment variables into an Ubuntu 18.04 system?
I am not so into Linux and I have the following problem related to how permanentlyunset some environment variables.
The problem is that each time that I log into my system, performing the env command ...
0
votes
0
answers
32
views
Why performing the env command I obtain different values of the environment variables declared into "/etc/environment"?
I am working on an Ubuntu 18.04.2 LTS system and I have the following doubt.
Into the /etc/environment file I have delcared the following variables:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/...
1
vote
0
answers
66
views
Trying to pass few variables to linux session from a flat file [duplicate]
I need to export around 10 variables to a session. To do this, I've put all these 10 variables in a flat file and trying to launch this flat file from shell using
sh flatfile
But these variables ...
2
votes
1
answer
2k
views
Why on printenv I cannot see the HOSTNAME enviromental variable? [duplicate]
On my ubuntu machine where I rin the following command:
printenv | grep HOSTNAME
Shows no output whilst when I do the following on terminal:
echo ${HOSTNAME}
Output is shown. SO I wanted to know ...
0
votes
1
answer
2k
views
Bash shell in mac terminal and iterm2 don't honor proxy environment variables
I have a 2019 mac running MacOS 10.14.6. I've had it configured to use my company's corporate proxy for about a month and various command line programs such as curl, brew, and git behave as expected ...
1
vote
1
answer
628
views
Supervisor and Shell command discrepancy: export variable from file working for in supervisor but not in shell, why?
suppose there's a file into /tmp/confs.sh, that looks like:
export CONTAINER_CODE_PROJECT_ROOT="//var/www"
and it's used inside a supervisor configuration file like this:
[program:laravel-horizon]
...
1
vote
1
answer
5k
views
How do I create an environment variable "openssl"
I know my question may sound stupid but there's some problem I've been fighting with for the last 2 days.
I have a few versions of OpenSSL installed on Ubuntu server.
The one which is desired is ...
2
votes
2
answers
3k
views
script with "export" command in a crontab
I have this in cron tab: * * * * * /root/attente.sh and attente.sh : export attente=$(cat /root/switchboard.txt)
If I run export attente=$(cat /root/switchboard.txt) in a shell it works but not in ...
0
votes
0
answers
268
views
incomplete PATH env var in IntelliJ IDEA terminal
I have a .bashrc that sets PATH, and also sources another file that extends said variable and defines new ones.
Looks like in bash opened via IDEA terminal, the PATH extension from this sourced ...
0
votes
0
answers
35
views
Bash puzzle of the week
We're having a very strange puzzle related to character encodings and bash replacement, where we are passing a bash variable into a rake script that gets piped into a different bash variable, and I'm ...