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 -> kshscript -> program -> user asks for shell -> kshThat 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 $1When 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 -versionGNU 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 VERSIONThe same behavior between AIX 5.3 until 7. OBS: In Ubuntu this doesn't happen.
PS1 variable inheritance between scripts and programs using bash in AIX
bash;aix;prompt
An workaround:// C code snippet#define CMDPATTERN_PS1_PRESET export PS1='%s';$SHELL#define CMDPATTERN_PS1_NOSET $SHELLchar* cmdpattern = (userPS1!=NULL && *userPS1 != NULL) ?CMDPATTERN_PS1_PRESET :CMDPATTERN_PS1_NOSET;sprintf(shellcmd, cmdpattern, userPS1);system(shellcmd);So, if the user wants a custom PS1, in case it isn't inherited, it should be previsouly configured in the software. And can keep working in all shells and OSes.