All Questions
Tagged with bash environment-variables
527 questions
-1
votes
2
answers
105
views
How to check if env exist in bash?
What is the standard way, in bash, to check if an environment variable is set up? I'm a little confused between the following options:
! [ -z "${VAR}" ]
[ -n "${VAR}" ]
[ "${...
2
votes
1
answer
332
views
how to pass environment variables to singularity exec
I have a BASH pipeline which at a point runs a Singularity container with singularity exec as follows:
singularity exec --bind `pwd`:/folder --bind $d:/results <image>.sif <tool_command> -...
0
votes
1
answer
48
views
best way to load an .env file as exported variables
I find .env files to be funny things, is there a one line utility to do this:
set -o allexport
source .env
set +o allexport
I do not like flipping the shell settings like that, wouldn't it be nice if ...
5
votes
1
answer
419
views
Weird shell variable expansion in bash
The bash manual says "The environment for any simple command or function may be augmented temporarily by prefixing it with parameter assignments".
I also understand that exported variables ...
3
votes
2
answers
221
views
How to handle a missing environment variable set in `crontab`
I have a bash script that I need to be able to start from either:
cron
an interactive (logon) shell
This script needs to know whether it was started from cron, or started from an interactive shell. ...
0
votes
1
answer
82
views
With sudo, why are inline environment variables not read correctly without -E on some systems?
I have a bash script which logs into my bitwarden instance using the bw cli, in the following way:
test.sh:
#!/usr/bin/sh
set -e -o pipefail
bw logout --quiet || true
BW_CLIENTID=$(cat ./credentials....
0
votes
0
answers
25
views
How to update variable in outer scope in bash [duplicate]
I was using ChatGPT, it genereated code with errors that I needed to fix. Now it seems that the code is correct:
#!/bin/bash
root_dir="$HOME/Zdjecia/Artykuły/"
earliest_date=""
...
0
votes
1
answer
105
views
Return multi-line ssh output to separate variables?
RHEL 8.10
OpenSSH_8.0p1, OpenSSL 1.1.1k FIPS 25 Mar 2021
As expected, this line (with two embedded commands) returns two rows:
$ ssh -q remoteserver "ls -1 /proc/${p}/fd | wc -l ; ps -Ostate -p$...
0
votes
1
answer
94
views
Is there a tool that can print out a bash script with the variables substituted? [duplicate]
Say I have a bash script that takes some environment variables and parameters and substitutes those variables in a script.
Is there a tool that can show how the script with the substituted variables ...
9
votes
1
answer
600
views
Why is bash startup executed under non-interactive ssh
I see an unexplained difference in behavior with ssh on Linux and FreeBSD, and it is the FreeBSD behavior that I would expect from the plain language of the manpages. So, something extra happens on ...
0
votes
2
answers
37
views
How to add a path to PATH that involves a variable that needs to be evaluated?
say I want to add the current directory to path. I need to run echo "export PATH=$PATH:$(pwd)" >> ~/.bash_profile.
this expands $(pwd) like I wanted, but it also expands the $PATH ...
0
votes
1
answer
297
views
Set environment variables in a python script and use them in a chained call [duplicate]
I would like to set a couple of environment variables in a Python script, then use said environment variables in a chained call.
For example, a python script called set_env.py:
os.environ["MY_VAR&...
2
votes
2
answers
342
views
commands execution based on file size fails with no apparent issues
I was working on an array job for a small pipeline, and I happened to need a way to execute a specific command based on file size. I found this post and similar which describe how to do it. At the ...
14
votes
3
answers
1k
views
Why does setting a variable readonly in the outer scope prevent defining a local variable with the same name?
I've found nothing about this in all my searching.
In the code below, Bar1 acts like I'd expect a "regular" variable to act (since help declare says that -g is only "seen" in ...
0
votes
0
answers
27
views
Terminal does not use .bashrc variables, but recognized them [duplicate]
I have installed the latest Pop!_OS version on my new computer and wanted to set the following environment variables:
CC=/usr/bin/clang
CXX=/usr/bin/clang++
CMAKE_GENERATOR=Ninja
Instead of typing ...