Why does running bash w/ a null environment in recovery mode show less available commands?

When I execute bash in Recovery Mode from a null environment, the completion/available commands functionality lists about 200 commands but with bash in a login environment it will show the 319 I typically have available in Recovery on other computers. If it helps, all of the commands in the null environment are also present in the login environment's commands.


Why are there fewer commands available when executing bash from a null environment? Can anyone else confirm that they have 319 available?


Please don't answer if you don't use the terminal regularly. Thanks!

MacBook Pro TouchBar and Touch ID, macOS Sierra (10.12.5), null

Posted on Jun 21, 2017 5:02 PM

Reply
3 replies

Jun 21, 2017 6:17 PM in response to Diana.McCall

Hi! So do you have any idea why the two environments would have a different $PATH variable then? Is that just set by launchctl in each processes' environment variables?


Do you know what the $ expression for? I see $NAME a lot and assume it means, "fill in the blank with the right stuff." Trying to read the man page for any number of commands always bring me back to the man for builtins which I'm not able to get much out of.


These lines and other in bold kinda make me assume the worst -

  • BASH_REMATCH=([0]="t")

  • PIPESTATUS=([0]="1")

  • TMPDIR=/var/folders/r5/1p6hwyls48z168hky_59smjh0000gn/T/

  • SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.7JOUXAeHDe/Listeners

  • In case you see anything I'll paste what declare gives me:

    BASH=/bin/bash

    BASH_ARGC=()

    BASH_ARGV=()

    BASH_LINENO=()

    BASH_REMATCH=([0]="t")

    BASH_SOURCE=()

    BASH_VERSINFO=([0]="3" [1]="2" [2]="57" [3]="1" [4]="release" [5]="x86_64-apple-darwin16")

    BASH_VERSION='3.2.57(1)-release'

    COLUMNS=179

    DIRSTACK=()

    EUID=501

    GROUPS=()

    HISTFILE=/Users/test/.bash_sessions/182D6076-127B-43C3-8C75-EDBDDD7CC9B5.history new

    HISTFILESIZE=500

    HISTSIZE=500

    HOME=/Users/test

    HOSTNAME=MacOhSoSecure.local

    HOSTTYPE=x86_64

    IFS=$' \t\n'

    LANG=en_US.UTF-8

    LINES=56

    LOGNAME=test

    MACHTYPE=x86_64-apple-darwin16

    MAILCHECK=60

    OPTERR=1

    OPTIND=1

    OSTYPE=darwin16

    PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

    PIPESTATUS=([0]="1")

    PPID=1987

    PROMPT_COMMAND=update_terminal_cwd

    PS1='\h:\W \u\$ '

    PS2='> '

    PS4='+ '

    PWD=/Users/test

    SHELL=/bin/bash

    SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:moni tor

    SHELL_SESSION_DID_HISTORY_CHECK=1

    SHELL_SESSION_DID_INIT=1

    SHELL_SESSION_DIR=/Users/test/.bash_sessions

    SHELL_SESSION_FILE=/Users/test/.bash_sessions/182D6076-127B-43C3-8C75-EDBDDD7CC9 B5.session

    SHELL_SESSION_HISTFILE=/Users/test/.bash_sessions/182D6076-127B-43C3-8C75-EDBDDD 7CC9B5.history

    SHELL_SESSION_HISTFILE_NEW=/Users/test/.bash_sessions/182D6076-127B-43C3-8C75-ED BDDD7CC9B5.historynew

    SHELL_SESSION_HISTFILE_SHARED=/Users/test/.bash_history

    SHELL_SESSION_HISTORY=1

    SHELL_SESSION_TIMESTAMP_FILE=/Users/test/.bash_sessions/_expiration_check_timest amp

    SHLVL=1

    SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.7JOUXAeHDe/Listeners

    TERM=xterm-256color

    TERM_PROGRAM=Apple_Terminal

    TERM_PROGRAM_VERSION=388.1

    TERM_SESSION_ID=182D6076-127B-43C3-8C75-EDBDDD7CC9B5

    TMPDIR=/var/folders/r5/1p6hwyls48z168hky_59smjh0000gn/T/

    UID=501

    USER=test

    XPC_FLAGS=0x0

    XPC_SERVICE_NAME=0

    _=declare

    __CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0

    shell_session_delete_expired ()

    {

    if ( [ ! -e "$SHELL_SESSION_TIMESTAMP_FILE" ] || [ -z "$(find "$SHELL_SESSION_TIMESTAMP_FILE" -mtime -1d)" ] ); then

    local expiration_lock_file="$SHELL_SESSION_DIR/_expiration_lockfile";

    if shlock -f "$expiration_lock_file" -p $$; then

    echo -n 'Deleting expired sessions...';

    local delete_count=$(find "$SHELL_SESSION_DIR" -type f -mtime +2w -print -delete | wc -l);

    [ "$delete_count" -gt 0 ] && echo $delete_count' completed.' || echo 'none found.';

    ( umask 077;

    touch "$SHELL_SESSION_TIMESTAMP_FILE" );

    rm "$expiration_lock_file";

    fi;

    fi

    }

    shell_session_history_allowed ()

    {

    if [ -n "$HISTFILE" ]; then

    local allowed=0;

    if shopt -q histappend || [ -n "$HISTTIMEFORMAT" ]; then

    allowed=${SHELL_SESSION_HISTORY:-0};

    else

    allowed=${SHELL_SESSION_HISTORY:=1};

    fi;

    if [ $allowed -eq 1 ]; then

    return 0;

    fi;

    fi;

    return 1

    }

    shell_session_history_check ()

    {

    if [ ${SHELL_SESSION_DID_HISTORY_CHECK:-0} -eq 0 ]; then

    SHELL_SESSION_DID_HISTORY_CHECK=1;

    if shell_session_history_allowed; then

    shell_session_history_enable;

    fi;

    if [ "$PROMPT_COMMAND" = "shell_session_history_check" ]; then

    unset PROMPT_COMMAND;

    else

    if [[ $PROMPT_COMMAND =~ (.*)(; *shell_session_history_check *| *shell_session_history_check *; *)(.*) ]]; then

    PROMPT_COMMAND="${BASH_REMATCH[1]}${BASH_REMATCH[3]}";

    fi;

    fi;

    fi

    }

    shell_session_history_enable ()

    {

    ( umask 077;

    touch "$SHELL_SESSION_HISTFILE_NEW" );

    HISTFILE="$SHELL_SESSION_HISTFILE_NEW";

    SHELL_SESSION_HISTORY=1

    }

    shell_session_save ()

    {

    if [ -n "$SHELL_SESSION_FILE" ]; then

    echo -n 'Saving session...';

    ( umask 077;

    echo 'echo Restored session: "$(date -r '$(date +%s)')"' >|"$SHELL_SESSION_FILE" );

    declare -F shell_session_save_user_state > /dev/null && shell_session_save_user_state;

    shell_session_history_allowed && shell_session_save_history;

    echo 'completed.';

    fi

    }

    shell_session_save_history ()

    {

    shell_session_history_enable;

    history -a;

    if [ -f "$SHELL_SESSION_HISTFILE_SHARED" ] && [ ! -s "$SHELL_SESSION_HISTFILE" ]; then

    echo -ne '\n...copying shared history...';

    ( umask 077;

    cp "$SHELL_SESSION_HISTFILE_SHARED" "$SHELL_SESSION_HISTFILE" );

    fi;

    echo -ne '\n...saving history...';

    ( umask 077;

    cat "$SHELL_SESSION_HISTFILE_NEW" >> "$SHELL_SESSION_HISTFILE_SHARED" );

    ( umask 077;

    cat "$SHELL_SESSION_HISTFILE_NEW" >> "$SHELL_SESSION_HISTFILE" );

    : >|"$SHELL_SESSION_HISTFILE_NEW";

    if [ -n "$HISTFILESIZE" ]; then

    echo -n 'truncating history files...';

    HISTFILE="$SHELL_SESSION_HISTFILE_SHARED";

    HISTFILESIZE="$HISTFILESIZE";

    HISTFILE="$SHELL_SESSION_HISTFILE";

    HISTFILESIZE="$size";

    HISTFILE="$SHELL_SESSION_HISTFILE_NEW";

    fi;

    echo -ne '\n...'

    }

    shell_session_update ()

    {

    shell_session_save && shell_session_delete_expired

    }

    update_terminal_cwd ()

    {

    local url_path='';

    {

    local i ch hexch LC_CTYPE=C LC_ALL=;

    for ((i = 0; i < ${#PWD}; ++i))

    do

    ch="${PWD:i:1}";

    if [[ "$ch" =~ [/._~A-Za-z0-9-] ]]; then

    url_path+="$ch";

    else

    printf -v hexch "%02X" "'$ch";

    url_path+="%${hexch: -2:2}";

    fi;

    done

    };

    printf '\e]7;%s\a' "file://$HOSTNAME$url_path"

    }

    Jun 22, 2017 9:55 AM in response to chase_daniel

    This info doesn't show what was going on as bash started up. This link: Bash startup scripts on Linux and Mac OS X (Example) describes the startup scripts bash reads as it starts in different modes. You need to determine the mode, and check the corresponding scripts to understand how the shell configures itself, starting with a blank slate. Please don't post the scripts. Read them yourself and see how the PATH is set.

    This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

    Why does running bash w/ a null environment in recovery mode show less available commands?

    Welcome to Apple Support Community
    A forum where Apple customers help each other with their products. Get started with your Apple Account.