Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
506
votes
6
answers
486844
views
What does "LC_ALL=C" do?
What does the `C` value for `LC_ALL` do in Unix-like systems? I know that it forces the same locale for all aspects but what does `C` do?
What does the
C
value for LC_ALL
do in Unix-like systems?
I know that it forces the same locale for all aspects but what does C
do?
jcubic
(10310 rep)
Aug 22, 2013, 07:32 AM
• Last activity: Jul 30, 2025, 06:10 AM
12
votes
4
answers
24838
views
How can I preserve an environment variable across su -?
I export `LC_ALL="en_US.UTF-8"` (via `sendEnv` in ssh_config) when using ssh to remote systems. When I `su - user123` this variable is reset by the login shell. Is there a way to preserve this variable (as well as other `LC_xxx` variables) when executing a login shell as another user on the remote s...
I export
LC_ALL="en_US.UTF-8"
(via sendEnv
in ssh_config) when using ssh to remote systems. When I su - user123
this variable is reset by the login shell. Is there a way to preserve this variable (as well as other LC_xxx
variables) when executing a login shell as another user on the remote system?
I realize I could export the variable by hand after executing the shell, or an entry in ~/.bashrc
of the target user, however I'd rather try to preserve the original values as sent by ssh
if possible. Thanks.
**EDIT**: I do need specific parts of the user's environment initialized which is why su -
is used. I would only want to preserve LC_xxx
Server Fault
(577 rep)
Jan 30, 2017, 06:03 PM
• Last activity: Jul 23, 2025, 06:36 AM
51
votes
3
answers
48326
views
change environment of a running process
How might it be possible to alter some variable in the `env` of an already running process, for example through `/proc/PID/environ?` That "file" is `read-only`. Need to change or unset the DISPLAY variable of a long-running batch job without killing it.
How might it be possible to alter some variable in the
env
of an already running process, for example through /proc/PID/environ?
That "file" is read-only
.
Need to change or unset the DISPLAY variable of a long-running batch job without killing it.
Marcos
(2353 rep)
May 9, 2012, 09:02 AM
• Last activity: Jul 18, 2025, 12:26 PM
38
votes
6
answers
86473
views
Complete view of where the PATH variable is set in bash
I've read in a couple of places that the `PATH` is set in `/etc/profile` or the `.profile` file that's in the home dir. Are these the only places that the path is set in? I want a better understanding of it. In the `/etc/profile` file, as the following comment says `"system-wide .profile file for th...
I've read in a couple of places that the
PATH
is set in /etc/profile
or the .profile
file that's in the home dir.
Are these the only places that the path is set in? I want a better understanding of it.
In the /etc/profile
file, as the following comment says "system-wide .profile file for the Bourne shell"
. Does that mean that profile files are the main configuration files for bash?
In that file I don't see the PATH
var being set at all. In the .profile
file in the home directory there's this line:
PATH="$HOME/bin:$PATH"
That's resetting PATH
by the looks because it's concatenating the already set $PATH
string with $HOME/bin:
right? But if etc/profile
and ~/.profile
are the only files setting PATH
where is $PATH
coming from in that line of code if it's not defined in /etc/profile
?
Can someone experienced please give a broad and detailed explanation of the PATH
variable? Thanks!
Larry Lawless
(491 rep)
Sep 7, 2015, 08:04 AM
• Last activity: Jul 16, 2025, 12:29 PM
2
votes
1
answers
5796
views
sudo: sorry, you are not allowed to set the following environment variables
I have created few aliases, that I source to shell: alias apti="apt-fast install -y" alias aptr="apt-fast remove -y" alias aptp="apt-fast purge -y" alias apts="aptitude search" alias aptu="sudo dpkg --configure -a; apti -f; apt-fast update; apt-fast upgrade -y; apt-fast full-upgrade -y; apt-fast aut...
I have created few aliases, that I source to shell:
alias apti="apt-fast install -y"
alias aptr="apt-fast remove -y"
alias aptp="apt-fast purge -y"
alias apts="aptitude search"
alias aptu="sudo dpkg --configure -a; apti -f; apt-fast update; apt-fast upgrade -y; apt-fast full-upgrade -y; apt-fast autoremove -y"
and then added exceptions to /etc/sudoers:
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
Cmnd_Alias APT=/usr/local/bin/apt
Cmnd_Alias DPKG=/usr/bin/dpkg
Cmnd_Alias APTGET=/usr/bin/apt-get
Cmnd_Alias APTITUDE=/usr/bin/aptitude
Cmnd_Alias APTFAST=/usr/sbin/apt-fast
Cmnd_Alias PM_SUSPEND=/usr/sbin/pm-suspend
myuser ALL=(ALL:ALL) NOPASSWD: APT, DPKG, APTGET, APTITUDE, PM_SUSPEND, APTFAST
and it worked fine for years. But few weeks ago (linux mint update?) it started giving me error.
$ apti iridium-browser
sudo: sorry, you are not allowed to set the following environment variables: DEBUG, LCK_FILE, DOWNLOADBEFORE, _APTMGR, APTCACHE, DLDIR, DLLIST, LISTDIR, _MAXNUM, _MAXCONPERSRV, _SPLITCON, _MINSPLITSZ, _PIECEALGO, aptfast_prefix, APT_FAST_TIMEOUT
In /etc/sudoers.d I have two files: README and mintupdate. I have not edited any of them. Only not commented lines are:
Cmnd_Alias UPDATE = /usr/lib/linuxmint/mintUpdate/checkAPT.py
ALL ALL = NOPASSWD:UPDATE
As far as I can see, I am not setting any environment variables that are lissted. What am I doing wrong?
spam
(183 rep)
Aug 2, 2017, 09:01 PM
• Last activity: Jul 15, 2025, 04:45 AM
1
votes
2
answers
2020
views
How to debug the Networkmanager-dispatcher-variables
I want to debug a script that contains Networkmanager-dispacher-variables like DEVICE_IFACE, IP4_GATEWAY. The [Networkmanager-manual][1] describes these variables but doesn't mention how to debug them. I searched a lot but i am unable to figure out how to get the value of these variables. When i ech...
I want to debug a script that contains Networkmanager-dispacher-variables like DEVICE_IFACE, IP4_GATEWAY. The Networkmanager-manual describes these variables but doesn't mention how to debug them.
I searched a lot but i am unable to figure out how to get the value of these variables. When i echo on the command line like echo ${DEVICE_IFACE} i get no value.
alixander
(111 rep)
Aug 28, 2018, 09:28 AM
• Last activity: Jul 13, 2025, 06:03 PM
8
votes
1
answers
4844
views
Is is possible to export all variables obtained from sourcing a file?
Say I have a file called `variables.sh` that sets two variables. foo=bar bar=foo If I `source` this file I can use these variables in the current shell, but if I want to use it in a second shell script I would have to export them instead, so the file would have to look like this: export foo=bar expo...
Say I have a file called
variables.sh
that sets two variables.
foo=bar
bar=foo
If I source
this file I can use these variables in the current shell, but if I want to use it in a second shell script I would have to export them instead, so the file would have to look like this:
export foo=bar
export bar=foo
It is possible to do some kind of source
+ export
or do I have to change variables.sh
so that there is export
before every variable is set?
DisplayName
(12016 rep)
Oct 14, 2020, 10:32 PM
• Last activity: Jul 7, 2025, 12:39 PM
3
votes
2
answers
2300
views
Allow user to run command as another user with their environment in sudoers
So, I have an entry that looks like this in my sudoers file: user1 ALL=(user2) NOPASSWD: /scripts/dir/ This allows user1 to run all executables under `/scripts/dir/` as user2 without entering their password using a command like `sudo -u user2 /scripts/dir/script `. However, I ran into issues where t...
So, I have an entry that looks like this in my sudoers file:
user1 ALL=(user2) NOPASSWD: /scripts/dir/
This allows user1 to run all executables under
/scripts/dir/
as user2 without entering their password using a command like sudo -u user2 /scripts/dir/script
. However, I ran into issues where the executables expect to be run with user2's environment ($PATH, $DISPLAY
, etc). user1 can accomplish that by running something like sudo -iu user2 /scripts/dir/script
which simulates a login shell, but with the above sudoers entry, this doesn't work and they're prompted to enter their password. Is there a sudoers entry that will alow user1 to run this command or at least be able to source user2's .bashrc, .cshrc, etc. when running commands?
I have found the SETENV
option, but that allows user1 to preserve their existing environment, not take on user2's environment. I could do source /home/user2/.bashrc
followed by sudo -Eu user2 /scripts/dir/script
; this would give user1 user2's environment which will be preserved by the -E
option, but this assumes that user1 has read access to the .bashrc
file and that the script does not try to execute any commands that user1 does not have permission to run.
The sudoers man page states the following about the -i
option to sudo
:
> As a special case, if sudo's -i option (initial login) is specified, sudoers will initialize the environment regardless of the value of env_reset. The DISPLAY, PATH and TERM variables remain unchanged; HOME, MAIL, SHELL, USER, and LOGNAME are set based on the target user. On AIX (and Linux systems without PAM), the contents of /etc/environment are also included. On BSD systems, if the use_loginclass flag is enabled, the path and setenv variables in /etc/login.conf are also applied. All other environment variables are removed.
which seems to indicate that it's possible to provide the -i
option with some sudoers configuration, perhaps by giving user1 permission to run ALL
commands or specifically allowing the -i
option in sudoers, but I'm hoping there is a more fine-grained way of achieving this. Also, it seems to indicate that PATH
and DISPLAY
will come from user1's environment which is not what I want.
Of course, I could give user1 more permissions than necessary in order to accomplish this, but that presents security risks.
dramzy
(131 rep)
Jan 21, 2017, 05:06 PM
• Last activity: Jul 6, 2025, 11:07 PM
0
votes
0
answers
35
views
LibreOffice crashes with Miniconda3 in path
this is a post that has workaround but not an explanation ---- Sometime in last 4 weeks my LibreOffice on my debian started crashing. Not producing window with eg. LOWriter, just a "crashed docs recovery" and a Soffice start window "choose from recent docs, create new" I think it's not relevant, but...
this is a post that has workaround but not an explanation
----
Sometime in last 4 weeks my LibreOffice on my debian started crashing. Not producing window with eg. LOWriter, just a "crashed docs recovery" and a Soffice start window "choose from recent docs, create new"
I think it's not relevant, but reported version is "LibreOffice 25.2.3.2 520(Build:2)" on debian trixie
indication was only this error output in console
> soffice --writer (base)
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
# or at most
> lowriter (base)
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
terminate called recursively
no other indication, running with --backtrace
yielded no success either (i can share the log, or strace log as well)
**However once I cleared env and removed "miniconda3 init code" from .bashrc it started working**
Can anybody please think of
1. explanation
2. proper way to detect/debug this kind of issue (since neither strace, gdb or anything helped me)
Thank you
Marek Sebera
(131 rep)
Jul 1, 2025, 04:37 PM
5
votes
1
answers
3055
views
Debian ignores PAM env variables (while Arch doesn't)
I have a weird issue with my Debian Sid system. I want to set a global environment variable in `/etc/environment`, which is supposed to be read by the `pam_env` module. Unfortunately, after having relogin in the system, the variable is not set. On another Arch Linux box, the same variable set in `et...
I have a weird issue with my Debian Sid system. I want to set a global environment variable in
/etc/environment
, which is supposed to be read by the pam_env
module. Unfortunately, after having relogin in the system, the variable is not set.
On another Arch Linux box, the same variable set in etc/environment
is defined as expected.
Just for testing, I tried to setup a local env variable in .pam_environment
and, again, on Debian it's not being defined while on Arch it is.
I'm using GDM on Debian and SDDM on Arch as login managers.
What am I missing? Which (PAM or GDM) configuration files should I look at?
EDIT:
output of grep pam_env /etc/pam.d/*
$ grep pam_env /etc/pam.d/*
/etc/pam.d/atd:auth required pam_env.so
/etc/pam.d/cron:# Read environment variables from pam_env's default files, /etc/environment
/etc/pam.d/cron:# and /etc/security/pam_env.conf.
/etc/pam.d/cron:session required pam_env.so
/etc/pam.d/cron:session required pam_env.so envfile=/etc/default/locale
/etc/pam.d/gdm-autologin:session required pam_env.so readenv=1
/etc/pam.d/gdm-autologin:session required pam_env.so readenv=1 envfile=/etc/default/locale
/etc/pam.d/gdm-launch-environment:session required pam_env.so readenv=1
/etc/pam.d/gdm-launch-environment:session required pam_env.so readenv=1 envfile=/etc/default/locale
/etc/pam.d/gdm-password:session required pam_env.so readenv=1
/etc/pam.d/gdm-password:session required pam_env.so readenv=1 envfile=/etc/default/locale
/etc/pam.d/login:# file /etc/security/pam_env.conf.
/etc/pam.d/login:session required pam_env.so readenv=1
/etc/pam.d/login:session required pam_env.so readenv=1 envfile=/etc/default/locale
/etc/pam.d/polkit-1:session required pam_env.so readenv=1 user_readenv=0
/etc/pam.d/polkit-1:session required pam_env.so readenv=1 envfile=/etc/default/locale user_readenv=0
/etc/pam.d/su:# file /etc/security/pam_env.conf.
/etc/pam.d/su:session required pam_env.so readenv=1
/etc/pam.d/su:session required pam_env.so readenv=1 envfile=/etc/default/locale
eang
(575 rep)
Jan 5, 2015, 05:46 PM
• Last activity: Jun 18, 2025, 09:07 PM
1
votes
2
answers
1077
views
Cannot Display Bash Functions within FZF Preview Window
**How do I get the FZF Preview Window to Display Functions from my Current Bash Environment?** I want to list my custom bash functions using FZF, and view the code of a selected function in the FZF Preview Window. However, it does not appear that the bash enviroment used by FZF to execute my command...
**How do I get the FZF Preview Window to Display Functions from my Current Bash Environment?**
I want to list my custom bash functions using FZF, and view the code of a selected function in the FZF Preview Window.
However, it does not appear that the bash enviroment used by FZF to execute my command can see the functions in my terminal bash environment. For example:
However, the following works:
$ declare -F | fzf --preview="type {3}"
/bin/bash: line 1: type: g: not found

$ declare -F
declare -f fcd
declare -f fz
declare -f g
$ type g
g is a function
g ()
{
search="";
for term in $@;
do
search="$search%20$term";
done;
nohup google-chrome --app-url "http://www.google.com/search?q=$search " > /dev/null 2>&1 &
}
declare -F | fzf --preview="echo {3}"
g # my function g()
One reason I suspect that the FZF Preview Window environment may not be able to see my terminal environment is because they have different process ID's.
$ echo $BASHPID
1129439
$ declare -F | fzf --preview="echo $BASHPID"
1208203
**How do I get the FZF Preview Window to Display Functions from my Current Bash Environment?**
user2514157
(225 rep)
Oct 21, 2022, 03:10 PM
• Last activity: Jun 11, 2025, 07:38 AM
2
votes
0
answers
1250
views
How do I prevent module load conflicts (environment modules)?
I am setting up [Environment Modules](http://modules.sourceforge.net/index.html) for a server and have two modules: `test1` and `test2`. The `test1` module needs `java/1.7.0` and `test2` needs `java/1.8.0`. If I use `prereqs`/`conflicts`, as seems to be standard practice, then I must load `java/1.7....
I am setting up [Environment Modules](http://modules.sourceforge.net/index.html) for a server and have two modules:
test1
and test2
.
The test1
module needs java/1.7.0
and test2
needs java/1.8.0
. If I use prereqs
/conflicts
, as seems to be standard practice, then I must load java/1.7.0
before loading test1
but if I load test2
afterwards and module switch java
to 1.8.0, test1
remains loaded and may still be functional in a warped manner.
The user, of course, has to do the module switch
themselves but is there any way to avoid this scenario so that test1
is unloaded if its prereq is.
It may be fairly easy to keep track of in the above scenario but if there are lots of tools each with multiple dependencies, I expect problems to arise. Is there some functionality of Environment Modules I'm not aware of or misunderstanding?
Tobi
(21 rep)
Feb 15, 2019, 12:50 PM
• Last activity: May 26, 2025, 11:14 AM
0
votes
2
answers
69
views
How to temporarily substitute the login shell for running a shell command/subprocess?
My login shell is Fish, but I would like to execute a shell command (`apt install ...`) **as if** my login shell was Bash. Is it possible to make a command/subprocess believe that my login shell is `/usr/bin/bash` without actually making it my login shell? Here is the context. When I try to install...
My login shell is Fish, but I would like to execute a shell command (
apt install ...
) **as if** my login shell was Bash.
Is it possible to make a command/subprocess believe that my login shell is /usr/bin/bash
without actually making it my login shell?
Here is the context.
When I try to install a certain package with apt install
, the post-installation script fails to start some service, and there is an error message from fish
about wrong syntax:
fish: Variables cannot be bracketed. In fish, please use "$XDG_RUNTIME_DIR".
XDG_RUNTIME_DIR="/run/user/$UID" DBUS_SESSION_BUS_ADDRESS="unix:path=${XDG_RUNTI
ME_DIR}/bus" systemctl --user start gpa
I tried executing apt install
from Bash, but this did not help.
However, if I change my login shell to Bash, then the installation succeeds without errors.
Of course, I do not want to change the login shell back and forth to execute one command, I hope there is a more appropriate solution.
(Of course, I do not understand why the post-installation script blindly uses the login shell which is not good for it.)
---
P.S. The package I was installing is GlobalProtect_deb-6.2.1.1-7.deb
for [Palo Alto GlobalProtect VPN]. Some versions are available online, for example here: https://myport.port.ac.uk/connect-to-the-vpn-on-your-linux-device
Alexey
(2310 rep)
May 24, 2025, 02:14 PM
• Last activity: May 24, 2025, 03:18 PM
2
votes
1
answers
2529
views
Exporting $PULSE_SERVER at start up
In order to run flatpak applications (like Discord or Spotify) I currently have to export the `$PUSLE_SERVER` in my `~/.zshrc` or `~/.bashrc` like so: export PULSE_SERVER=unix:/tmp/pulse-PKdhtXMmr18n/native After reading this [part][1] of the pulse audio FAQ I believe I can get this working by using...
In order to run flatpak applications (like Discord or Spotify) I currently have to export the
$PUSLE_SERVER
in my ~/.zshrc
or ~/.bashrc
like so:
export PULSE_SERVER=unix:/tmp/pulse-PKdhtXMmr18n/native
After reading this part of the pulse audio FAQ I believe I can get this working by using ~/.config/pulse/client.conf
.
I have tried adding either of the following two lines to my ~/.config/pulse/client.conf
:
default-server = unix:/tmp/pulse-PKdhtXMmr18n/native
And:
auto-connect-display = yes
NOTE: I tried the second because someone on the IRC suggested that flatpak may be looking at something related to X11 for the $PULSE_SERVER
.
After trying an env | grep PULSE
the $PULSE_SERVER
does not appear to be being set. Furthermore neither of these approaches seem to have any effect (in saying that the first seemed to interfere with the session start as it stopped my polybar
from starting, I have no idea why or how to debug this).
The main reason for wanting to define the $PULSE_SERVER
elsewhere is I don't want to have to declare it in each shell and I would like to keep all the pulse config in one place.
I originally tried adding the above export to my ~/.xprofile
(I use SDDM to start my session) however this stopped the pulse folder from being created in /tmp/
.
Additional Info: I am running void linux with the bspwm window manager.
Otis Wright
(121 rep)
Jan 2, 2019, 08:14 AM
• Last activity: May 24, 2025, 07:02 AM
1
votes
1
answers
5689
views
Uninstall Android Studio + SDK
I am using linux arch. I installed android according to [ArchWiki](https://wiki.archlinux.org/index.php/Android). I uninstalled every skd component and android studio using `pacman -Rs`. Also, I removed every hidden folder in the home directory that had something to do with android such `.android`,...
I am using linux arch. I installed android according to [ArchWiki](https://wiki.archlinux.org/index.php/Android) .
I uninstalled every skd component and android studio using
pacman -Rs
. Also, I removed every hidden folder in the home directory that had something to do with android such .android
, .gradle
, AndroidStudio. But the environment variable ANDROID_HOME
is still set and the following command
ps aux | grep 'adb'
returns adb -L tcp:5037 fork-server server --reply-fd 4
Where is the environment variable ANDROID_HOME set and what means adb -L tcp:5037 fork-server server --reply-fd 4
? Is android not properly uninstalled?
The command adb
returns bash: adb: command not found
EDIT:
In a */proc/pid/environ*, there are still things like
*/opt/android-sdk/platform-tools:/opt/android-sdk/tools:/opt/android-sdk/tools/bin*
user119589
Jun 21, 2017, 07:51 PM
• Last activity: May 23, 2025, 05:04 PM
152
votes
11
answers
425024
views
Script to change current directory (cd, pwd)
I want to run a script to simply change the current working directory: #!/bin/bash cd web/www/project But, after I run it, the current pwd remains unchanged! How can I do that?
I want to run a script to simply change the current working directory:
#!/bin/bash
cd web/www/project
But, after I run it, the current pwd remains unchanged! How can I do that?
Sony Santos
(1623 rep)
Dec 19, 2011, 07:55 AM
• Last activity: May 22, 2025, 02:54 AM
57
votes
1
answers
29888
views
Difference between (bash) shell variables which are exported and those which are not
Bash seems to differentiate between variables which are exported and those which are not. example: $ FOO=BAR $ set | grep FOO FOO=BAR $ env | grep FOO `set` sees the variable but `env` does not. $ export BAR=FOO $ set | grep FOO BAR=FOO FOO=BAR $ env | grep FOO BAR=FOO `set` sees both variables but...
Bash seems to differentiate between variables which are exported and those which are not.
example:
$ FOO=BAR
$ set | grep FOO
FOO=BAR
$ env | grep FOO
set
sees the variable but env
does not.
$ export BAR=FOO
$ set | grep FOO
BAR=FOO
FOO=BAR
$ env | grep FOO
BAR=FOO
set
sees both variables but env
sees only the exported variable.
I know that set
is a bash builtin and env
is not.
What are the differences between variables which are exported and those which are not?
Lesmana
(28027 rep)
Oct 25, 2010, 10:15 PM
• Last activity: May 21, 2025, 09:44 AM
-4
votes
1
answers
74
views
Are simple command variable assignments accessible in nested scripts? e.g., does `child.sh` have "FOO=BAR" when running "FOO=BAR ./parent.sh"?
Although this is easy to try and see, I was looking for the answer on StackOverflow and couldn't find it. That's why I'm asking and answering my question. I recommend [reading this][1] first. The answer is hinted at, but not directly stated. --- I have these two shell scripts: ``` $ cat parent.sh ec...
Although this is easy to try and see, I was looking for the answer on StackOverflow and couldn't find it. That's why I'm asking and answering my question.
I recommend reading this first. The answer is hinted at, but not directly stated.
---
I have these two shell scripts:
$ cat parent.sh
echo $(basename "$0")
echo "$FOO"
./child.sh
$ cat child.sh
echo $(basename "$0")
echo "$FOO"
What will be printed if I run this command: FOO=BAR ./parent.sh
Daniel Kaplan
(1070 rep)
May 17, 2025, 09:33 PM
• Last activity: May 17, 2025, 10:46 PM
2
votes
2
answers
2125
views
Preserve OLDPWD after logging out
I often need to go to the directory I was when I logged out of a server. I habitually use `cd -` for this purpose. However, after logging out and logging back in this does not work because apparently `OLDPWD` gets reset: $ cd - -bash: cd: OLDPWD not set Is there a way to preserve the value of `OLDPW...
I often need to go to the directory I was when I logged out of a server. I habitually use
cd -
for this purpose. However, after logging out and logging back in this does not work because apparently OLDPWD
gets reset:
$ cd -
-bash: cd: OLDPWD not set
Is there a way to preserve the value of OLDPWD
beyond a login session in bash?
Ketan
(9426 rep)
Oct 23, 2015, 12:02 AM
• Last activity: May 11, 2025, 06:47 PM
0
votes
0
answers
43
views
bash variable substitution inside heredoc delimiter: how does it work?
For a school project, I am tasked with making my own (simplified) shell, with bash being the reference point. This includes replicating heredoc behavior which was fun until I stumbled upon variable substitution INSIDE of the delimiter, as such: ```export TESTVAR=hello``` followed by cat hello > $TES...
For a school project, I am tasked with making my own (simplified) shell, with bash being the reference point. This includes replicating heredoc behavior which was fun until I stumbled upon variable substitution INSIDE of the delimiter, as such:
TESTVAR=hello
followed by
cat hello
> $TESTVAR
hello
As demonstrated here, typing the value of the variable manually does not end the heredoc, whereas typing $TESTVAR
does. Does this mean that variables are not substituted if they're inside of the delimiter?
Disabling variable substitution results in the same thing:
cat hello
> $TESTVAR
hello
And getting wild with the quotes also results in the same thing:
cat hello
> TVAR
> $TESTVAR
hello
TVAR
All evidence seems to point towards $TESTVAR
does not get substituted **because** it is part of a heredoc delimiter, but I can't find a definitive answer to this! Does anyone know?
Mika
(101 rep)
May 9, 2025, 01:58 PM
• Last activity: May 9, 2025, 02:17 PM
Showing page 1 of 20 total questions