Exported variable in bashrc file not visible when running as another user
Your problem is that .bashrc
is configure explicitly to only run for interactive shells. Look at the top of /home/foouser/.bashrc
:
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
If you add a set -x
to your /tmp/bootstrap.sh
script, you will see when you execute it the following:
+ echo 'export FOO=foo'
+ . /home/foouser/.bashrc
++ case $- in
++ return
+ echo 'sourced foouser bashrc'
sourced foouser bashrc
+ set
+ grep FOO
There you can see it hits the return
command in the case statement.
You can force an interactive shell with the -i
option:
root@ed3085a447ad:/# su - foouser -c 'bash -i -c /tmp/bootstrap.sh'
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
sourced foouser bashrc
FOO=foo
Node command not found when bash script is run through desktop icon
A workmate solved the problem. Just add
PATH="/home/myuser/.nvm/versions/node/v12.14.1/bin:$PATH"
after the #!/bin/bash
line.
So the bash script is finally:
#!/bin/bash
PATH="/home/myuser/.nvm/versions/node/v12.14.1/bin:$PATH"
cd /home/myuser/app/todo_app/
node ./app.js
echo "Bye"
$SHELL
Add input and show output in terminal from .desktop file
Got it working, First install lxterminal and then edit Openconnect.desktop file.
[Desktop Entry]
Version=1.0
Name=Openconnect
Comment=This is my VPN Connection
Exec=lxterminal --command="/home/support/Documents/Openconnect.sh"
Icon=/home/support/Documents/openvpn.png
Terminal=false
Type=Application
Categories=Utility;Application;
how to make functions visible to bash scripts?
/etc/bashrc
, ~/.bashrc
are not read when not running in an interactive mode.
You might see something similar to
case $- in
*i*) ;;
*) return;;
esac
or
[ -z "$PS1" ] && return
in your ~/.bashrc
.
Consider adding your function to ~/.profile
or to ~/.bash_profile
(if the latter exists).
Related Topics
Sed: -I May Not Be Used with Stdin on MAC Os X
Decrypt Obfuscated Perl Script
Automated Test Tools for Linux/Ncurses
Linux - Without Hardware Soundcard, Capture Audio Playback, and Record It to File
How to Set Cronjob with Non-Root User
Zsh Menu Completion Causes Problems After Zle Reset-Prompt
"Cannot Execute Binary File" When Trying to Run a Shell Script on Linux
.Bashrc Not Read When Shell Script Is Invoked from Desktop Shortcut
Linux Run Kernel Probe Systemtap Script Failed with Semantic Error: No Match"
Overlay Two Postscript Files (Command Line Approach)
Why Mongodb Performance Better on Linux Than on Windows
Using Perf Probe to Monitor Performance Stats During a Particular Function
Case-Insensitive Glob on Zsh/Bash
Tcp: Server Sends [Rst, Ack] Immediately After Receiving [Syn] from Client
Rename File Command in Unix with Timestamp
Using Curl in a Bash Script and Getting Curl: (3) Illegal Characters Found in Url