diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-05-19 15:37:50 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-05-19 15:39:32 +0200 |
commit | 0c3601936915d3d625683388c62c561de96a47da (patch) | |
tree | b427f860b4b43e2214a031589ecffa188a946ac9 | |
parent | 08fb82c80cf06b776822b8388c3863e7c5565a74 (diff) | |
download | busybox-w32-0c3601936915d3d625683388c62c561de96a47da.tar.gz busybox-w32-0c3601936915d3d625683388c62c561de96a47da.tar.bz2 busybox-w32-0c3601936915d3d625683388c62c561de96a47da.zip |
hush: set default PS1/2 only if we interactive
"env - hush SCRIPT" invocation (that is, with empty environment)
should not show PS1/2 in "set" output.
function old new delta
hush_main 1070 1075 +5
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/hush.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/shell/hush.c b/shell/hush.c index 629b7ff92..2b9abbdfd 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -9888,14 +9888,6 @@ int hush_main(int argc, char **argv) | |||
9888 | /* Export PWD */ | 9888 | /* Export PWD */ |
9889 | set_pwd_var(SETFLAG_EXPORT); | 9889 | set_pwd_var(SETFLAG_EXPORT); |
9890 | 9890 | ||
9891 | #if ENABLE_HUSH_INTERACTIVE && ENABLE_FEATURE_EDITING_FANCY_PROMPT | ||
9892 | /* Set (but not export) PS1/2 unless already set */ | ||
9893 | if (!get_local_var_value("PS1")) | ||
9894 | set_local_var_from_halves("PS1", "\\w \\$ "); | ||
9895 | if (!get_local_var_value("PS2")) | ||
9896 | set_local_var_from_halves("PS2", "> "); | ||
9897 | #endif | ||
9898 | |||
9899 | #if BASH_HOSTNAME_VAR | 9891 | #if BASH_HOSTNAME_VAR |
9900 | /* Set (but not export) HOSTNAME unless already set */ | 9892 | /* Set (but not export) HOSTNAME unless already set */ |
9901 | if (!get_local_var_value("HOSTNAME")) { | 9893 | if (!get_local_var_value("HOSTNAME")) { |
@@ -9907,6 +9899,8 @@ int hush_main(int argc, char **argv) | |||
9907 | /* IFS is not inherited from the parent environment */ | 9899 | /* IFS is not inherited from the parent environment */ |
9908 | set_local_var_from_halves("IFS", defifs); | 9900 | set_local_var_from_halves("IFS", defifs); |
9909 | 9901 | ||
9902 | /* PS1/PS2 are set later, if we determine that we are interactive */ | ||
9903 | |||
9910 | /* bash also exports SHLVL and _, | 9904 | /* bash also exports SHLVL and _, |
9911 | * and sets (but doesn't export) the following variables: | 9905 | * and sets (but doesn't export) the following variables: |
9912 | * BASH=/bin/bash | 9906 | * BASH=/bin/bash |
@@ -10278,14 +10272,23 @@ int hush_main(int argc, char **argv) | |||
10278 | * (--norc turns this off, --rcfile <file> overrides) | 10272 | * (--norc turns this off, --rcfile <file> overrides) |
10279 | */ | 10273 | */ |
10280 | 10274 | ||
10281 | if (!ENABLE_FEATURE_SH_EXTRA_QUIET && G_interactive_fd) { | 10275 | if (G_interactive_fd) { |
10282 | /* note: ash and hush share this string */ | 10276 | #if ENABLE_HUSH_INTERACTIVE && ENABLE_FEATURE_EDITING_FANCY_PROMPT |
10283 | printf("\n\n%s %s\n" | 10277 | /* Set (but not export) PS1/2 unless already set */ |
10284 | IF_HUSH_HELP("Enter 'help' for a list of built-in commands.\n") | 10278 | if (!get_local_var_value("PS1")) |
10285 | "\n", | 10279 | set_local_var_from_halves("PS1", "\\w \\$ "); |
10286 | bb_banner, | 10280 | if (!get_local_var_value("PS2")) |
10287 | "hush - the humble shell" | 10281 | set_local_var_from_halves("PS2", "> "); |
10288 | ); | 10282 | #endif |
10283 | if (!ENABLE_FEATURE_SH_EXTRA_QUIET) { | ||
10284 | /* note: ash and hush share this string */ | ||
10285 | printf("\n\n%s %s\n" | ||
10286 | IF_HUSH_HELP("Enter 'help' for a list of built-in commands.\n") | ||
10287 | "\n", | ||
10288 | bb_banner, | ||
10289 | "hush - the humble shell" | ||
10290 | ); | ||
10291 | } | ||
10289 | } | 10292 | } |
10290 | 10293 | ||
10291 | parse_and_run_file(hfopen(NULL)); /* stdin */ | 10294 | parse_and_run_file(hfopen(NULL)); /* stdin */ |