Welcome to the Linux Foundation Forum!

bash history delete not executing

Daniel Lamb
Daniel Lamb Posts: 1
edited May 1 in Command Line/Scripting

I've written this alias for deleting history entries in consecutive order or reverse order:

delHist () 
{ 
    ( a=${1%-*};
    b=${1#*-};
    if [ $b -lt $a ]; then
        for ((a; a>=b; a--))
        do
            set -x;
            history -d $a;
            set +x;
        done;
    else
        set -x;
        history -d $1;
        set +x;
    fi )
}

A use example would be delHist 52-50 to delete history items 52, 51 and 50 in that order. When it comes to executing the code at line 9 history -d ## the syntax is correct but the items are not deleted from the history in the bash shell session.

Similarly, if the example is delHist 50-52 the command at line 14 would be history -d 50-52. That is what is displayed in the execution but the items are not deleted from the history in the bash shell session.

Is there syntax I am missing so that the history -d ## executes and in fact deletes the entry from history?

Categories

Upcoming Training