The variable expansion in the "bash -c" is happening before "bash -c" is run; you need to do something like:
bash -c "source /neuro/arch/scripts/neuro-fs stable;echo \$XAPPLRESDIR;"
문제
I am trying to source a bash script inside a bash -c "..."
command but it doesn't work.
If I run the command outside of the bash -c "..."
it works.
I need to use bash -c "..."
because I want to ensure people are using Bash (no sh, tcsh, etc.)
working:
bash> source /neuro/arch/scripts/neuro-fs stable;echo $XAPPLRESDIR;
/neuro/arch/x86_64-Linux/packages/matlab/MATLAB_Compiler_Runtime/current/X11/app-default
not working:
bash> bash -c "source /neuro/arch/scripts/neuro-fs stable;echo $XAPPLRESDIR;"
In the Bash script, we define XAPPLRESDIR
as follows:
export XAPPLRESDIR=/neuro/arch/x86_64-Linux/packages/matlab/MATLAB_Compiler_Runtime/current/X11/app-defaults
#!/bin/bash
at the beginning of the script or not doesn't seem to make any difference.
Is export a "bad" practice in this case?
해결책
The variable expansion in the "bash -c" is happening before "bash -c" is run; you need to do something like:
bash -c "source /neuro/arch/scripts/neuro-fs stable;echo \$XAPPLRESDIR;"