I have a Python script that helps us log into AWS CLI regardless of the operating system. On Linux, this script generates the following output:
set +o history
export AWS_ACCESS_KEY_ID=secret_value
export AWS_SECRET_ACCESS_KEY=very_secret_value
set -o history
When an operator copies and pastes these commands into a shell, the access key and secret key are not saved in the shell history due to the set +o history and set -o history commands.
However, when running the same script on macOS, this doesn’t work as expected. Instead, all the commands are saved as a single history entry with n between the lines.
I wanted to ask if there’s a solution to my problem.
What I’ve tried so far:
- Using setopt HIST_NO_STORE to disable history for specific commands.
- Using HIST_IGNORE_SPACE to avoid saving commands that start with a space.
- Using fc -R with the here-string method (fc -R <<< $’command’).
- Prefixing commands with spaces when pasted, one at a time.
I want to prevent multiple commands (when pasted into the terminal) from being saved in the history on macOS. Ideally, I want each command to be treated as separate history entries.
noodleDMX is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4