a script calls another script which calls "bash" inside
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The enter_antoher_bash_env.sh will setup a new shell environment, call "bash". The rest commands need to run under the new env. (I cannot change this script too. )
If I run these command one by one manually, it works of course. If I put them into a script, enter_another_bash_env.sh won't return because it calls "bash" command inside.
I tried use "." or "exec", no luck. Any idea how to do it? Thanks.
You cannot change script enter_another_bash_env.sh
Script enter_another_bash_env.sh includes bash --rcfile ~/.new_bash_rc
If so:
Does enter_another_bash_env.sh return after running bash --rcfile ~/.new_bash_rc?
Can you change ~/.new_bash_rc? (I think the answer has to be yes).
If script enter_another_bash_env.sh is not secret it might help if you posted it here (or attached it if it is long). If posting it here, please use code tags (that's a link to instructions or you may prefer to use "Advanced Edit" mode which has a # button for code tags).
You said you ~couldn't~ modify the "enter_another_bash_env.sh"? If so that is going to be a very large problem because the existing way it's setup is not going to allow you to automate it the correct way, you might still be able to do it via expect... maybe.
The correct way would be remove the bash --rcfile ~/.new_bashrc line completely and add the following lines to your script:
Actually lets stop. Since this is a bash script calling a bash script... why aren't you just getting rid of the headache and having your script do everything you need it to do and not dealing with their external script in the first place?
eg:
Code:
#!/bin/bash
# command 1
# where you used to call external script... (using exec or whatever)
export SDK_VERSION=moblin-sdk-0.10
export MOBLIN_TOOLCHAIN=$HOME/dragon/${SDK_VERSION}/moblin-cross-toolchain
if [ ! -d ${MOBLIN_TOOLCHAIN} ]; then
echo ""
echo "ERROR: can NOT find Moblin build toolchain directory: ${MOBLIN_TOOLCHAIN}"
echo ""
echo "please edit envsetup.sh and set the value of \${MOBLIN_TOOLCHAIN} to the \"mobln-cross-toolchain\" directory in the SDK"
echo ""
else
###################################################
# don't change the below content!!! #
###################################################
cat > ~/.moblin-sdkrc << EOF
## set to new value
export PATH=$MOBLIN_TOOLCHAIN/bin:$PATH
export MOBLIN_SYS=$MOBLIN_TOOLCHAIN/i586-moblin-linux/sys-root
export PKG_CONFIG_SYSROOT_DIR=\${MOBLIN_SYS}
export PKG_CONFIG_PATH=\${MOBLIN_SYS}/usr/lib/pkgconfig:\${MOBLIN_SYS}/usr/share/pkgconfig
export host_alias=i586-moblin-linux
if [ `id -u` = 0 ]; then
export PS1="\[\e[31;1m\][$SDK_VERSION]:\[\e[35;1m\]\w# \[\e[0m\]"
else
export PS1="\[\e[31;1m\][$SDK_VERSION]:\[\e[35;1m\]\w$ \[\e[0m\]"
fi
if [ -x /usr/bin/dircolors ]; then
eval "\`dircolors -b\`"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
#alias grep='grep --color=auto'
#alias fgrep='fgrep --color=auto'
#alias egrep='egrep --color=auto'
fi
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
EOF
fi
source ~/.moblin-sdkrc
# command 2 etc...
Honestly, from what i can see of their script it only really ever needs ran once to generate the .moblin-sdkrc file (for each user, once generated once for your system it could be added to skel or copied to the home directories of everyone who needs it)... not every time you want to do something. Except for some exports (which are legitimately probably needed) all it's doing is changing the prompt... you could add the exports to the .bashrc and be done with your script, their script, etc.
I assume these command will start bash shell with the new rc file, execute a command and exit. But it doesn't. The command is running under the regular bash shell environment.
I prefer this solution, if it work. Since my main script will continue without any pollution from the rc file.
Yes, bash' --rcfile option implies an interactive shell. It's useful to run a command in a terminal emulator from a desktop "launcher" and have the window left open so you can see the command output.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.