bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Probable recursion in particular alias


From: Ante Perić
Subject: Re: Probable recursion in particular alias
Date: Thu, 10 Jan 2019 07:30:18 +0100

Yes, certainly. I've also minimized the .bashrc and .bash_profile in here to 
what will also reproduce. Running "foo" here will peg my CPU down.

zrak:~ synthmeat$ alias; declare -f
alias foo='     echo "bar"      '
shell_session_delete_expired () 
{ 
    if ( [ ! -e "$SHELL_SESSION_TIMESTAMP_FILE" ] || [ -z "$(/usr/bin/find 
"$SHELL_SESSION_TIMESTAMP_FILE" -mtime -1d)" ] ); then
        local expiration_lock_file="$SHELL_SESSION_DIR/_expiration_lockfile";
        if /usr/bin/shlock -f "$expiration_lock_file" -p $$; then
            echo -n 'Deleting expired sessions...';
            local delete_count=$(/usr/bin/find "$SHELL_SESSION_DIR" -type f 
-mtime +2w -print -delete | /usr/bin/wc -l);
            [ "$delete_count" -gt 0 ] && echo $delete_count' completed.' || 
echo 'none found.';
            ( umask 077;
            /usr/bin/touch "$SHELL_SESSION_TIMESTAMP_FILE" );
            /bin/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;
    /usr/bin/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: "$(/bin/date -r '$(/bin/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;
        /bin/cp "$SHELL_SESSION_HISTFILE_SHARED" "$SHELL_SESSION_HISTFILE" );
    fi;
    echo -ne '\n...saving history...';
    ( umask 077;
    /bin/cat "$SHELL_SESSION_HISTFILE_NEW" >> "$SHELL_SESSION_HISTFILE_SHARED" 
);
    ( umask 077;
    /bin/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"
}
zrak:~ synthmeat$ bash --version
GNU bash, version 5.0.0(1)-release (x86_64-apple-darwin18.2.0)
Copyright (C) 2019 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.
zrak:~ synthmeat$ cat .bashrc 
#!/usr/bin/env bash

alias foo="\
        echo \"bar\" \
        "
zrak:~ synthmeat$ cat .bash_profile 
#!/usr/bin/env bash

if [ -n "$BASH_VERSION" ]; then
        if [ -f "$HOME/.bashrc" ]; then
                . "$HOME/.bashrc"
        fi
fi

> On Jan 9, 2019, at 18:21, Eduardo Bustamante <dualbus@gmail.com> wrote:
> 
> On Wed, Jan 9, 2019 at 4:59 AM Ante Perić <synthmeat@gmail.com> wrote:
> (...)
>> Description:
>> Having an alias of type:
>> alias bug="\
>>           echo \"no output, 100% cpu\" \
>>          "
>> in .bashrc will give no output, will not complete, and it will peg the CPU 
>> to 100%.
> 
> Can you share the output of (right after the interactive bash session
> starts up):
> 
> alias; declare -f




reply via email to

[Prev in Thread] Current Thread [Next in Thread]