How can I ensure that PS1 variable in AIX bash is inherited between cross calling of scripts and programs ?
Suppose a program gives to the user a shell instance such as the shell
command of vi
. This can be used in two ways, in one of them it's launched by a script (see the 2nd case below):
ksh prompt
->program
-> "user asks for shell" ->ksh
- script ->
program
-> "user asks for shell" ->ksh
That works well with ksh. But when the bash is used (in AIX), we noticed in the 2nd case that the PS1 variable isn't inherited, so it has the default value.
You can test it just using vi, create a script, like: runvi.sh
:
# blablabla
# vi $1
When we run the script and ask vi for the shell, the prompt is: sh-4.3$
Of course, when you run vi directly, and it asks for the shell, the prompt is your previously defined PS1.
The unique difference between the test above and the real program is that in the program the bash shows the PS1 with the value bash-4.3$
, so the issue with PS1 inheritance seems the same. This C program can shows it:
#include <stdlib.h>
main() { system("$SHELL"); }
BASH VERSION:
bash-4.3$ bash -version
GNU bash, version 4.3.30(1)-release (powerpc-ibm-aix5.1.0.0)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
AIX VERSION
The same behavior between AIX 5.3 until 7.
OBS: In Ubuntu this doesn't happen.
system("$SHELL -li")
to have it source your login config files. Many programs hardcode/bin/sh
as a "system shell": in that case, you have no control.