macOS Catalina /bin/sh vs /bin/bash and showing history with preceding hash

0

1

Not really a question but an observation. When I do sys ad on Linux, I like to precede commands with a hash '#' to proof-read what I am about execute, and also to leave a breadcrumb so that I can come back to it later on.

I've found out recently on macOS Catalina (this being my main workhorse now), that bash does not print lines in the history file with a preceding hash, that doe snot appear to be the case in othe flavours of Linux, i.e. RHEL, Ubuntu

$ echo $SHELL
/bin/bash
$ echo foo
foo
$ #echo bar
$ !:p
echo foo


$ echo $SHELL 
/bin/sh
$ echo foo
foo
$ #echo bar
$ !:p
#echo bar
$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.15
BuildVersion:   19A602

Outputs of $HISTIGNORE $HISTCONTROL

Sure

$ echo 0e"$SHELL\n$HISTIGNORE\n$HISTCONTROL"
/bin/sh


$ echo -e "$SHELL\n$HISTIGNORE\n$HISTCONTROL"
/bin/bash


meappy

Posted 2019-10-23T00:59:00.023

Reputation: 1

Can you show the output of echo $HISTCONTROL and echo $HISTIGNORE? – Spiff – 2019-10-23T01:22:20.553

Hi @Spiff sure, I've editted my post with the output – meappy – 2019-10-23T03:32:21.127

macOS ships a really old version of bash. – egmont – 2019-10-24T09:10:55.047

Answers

0

Just want to answer my question

@egmont you're right bash is shipped with a really old version

My solution was to upgrade bash.

This post in Medium clearly explains how to upgrade bash on MacOS, and is exactly what I did to get commands preceded with # to be printed in my history again

https://itnext.io/upgrading-bash-on-macos-7138bd1066ba

I'll post setps to upgrae bash in MacOS with Homebrew

$ brew install bash 
$ sudo echo /usr/local/bin/bash >> /etc/shells 
$ sudo chsh -s /usr/local/bin/bash # for the current user

Here are some tests before and after upgrading bash

Before upgrading bash

$ echo foo
foo
$ #echo bar
$ !:p
echo foo
$ bash --version
GNU bash, version 5.0.11(1)-release (x86_64-apple-darwin19.0.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.

After upgrading bash

$ echo foo 
foo
$ #echo bar
$ !:p
#echo bar
$ bash--version
-bash: bash--version: command not found
Geralds-MacBook-Pro:~ gerald$ bash --version
GNU bash, version 5.0.11(1)-release (x86_64-apple-darwin19.0.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.

meappy

Posted 2019-10-23T00:59:00.023

Reputation: 1

0

That appears to be unique to Catalina. I have not upgraded yet.

$ echo 

$ # hello 
$ !:p 
# hello  
$

I use this "feature" as well so it would be useful to find a way to sort that.

For completeness:

$ echo \"$HISTIGNORE\" 
""
$ echo \"$HISTCONTROL\" 
""

JamesIsIn

Posted 2019-10-23T00:59:00.023

Reputation: 41