0

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


3
  • Can you show the output of echo $HISTCONTROL and echo $HISTIGNORE?
    – Spiff
    Commented Oct 23, 2019 at 1:22
  • Hi @Spiff sure, I've editted my post with the output
    – meappy
    Commented Oct 23, 2019 at 3:32
  • macOS ships a really old version of bash.
    – egmont
    Commented Oct 24, 2019 at 9:10

2 Answers 2

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\" 
""
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .