Software⏱️ 3 min read📅 2026-06-15

How to Fix: in bash, why error on history -s "- ", history -s '- '?

Bash history -s option error fix for invalid dash followed by blank.

Quick Answer: Use single quotes around the argument string to prevent bash from parsing it as an option.

The error 'bash: history: - : invalid option' occurs when the bash shell attempts to parse the argument string as a bash option, causing it to fail. This issue affects users who rely on the 'history -s' command to store and retrieve shell history.

This error can be frustrating for users who are accustomed to using the 'history -s' command without issues. However, the solution is straightforward and does not require any significant changes to the user's workflow.

💡 Why You Are Getting This Error

  • The primary cause of this error is the fact that bash interprets the '-' character as a special option. When the '-s' option is specified, bash expects the next argument to be a string containing the history file name. However, when the '--' separator is used, bash treats the following arguments as options rather than file names.
  • An alternative cause of this error could be due to the presence of other options or flags in the command line that are causing bash to misinterpret the '-s' option.

✅ Best Solutions to Fix It

Using the '--' separator to avoid option interpretation

  1. Step 1: To resolve this issue, use the '--' separator before the history file name when specifying the '-s' option. For example: `history -s -- "-"` and `history -s -- '-'`. This tells bash to treat the following arguments as file names rather than options.
  2. Step 2: By using the '--' separator, you ensure that bash correctly interprets the '-s' option and stores or retrieves the shell history without errors.

Avoiding special characters in the argument string

  1. Step 1: Alternatively, you can avoid using special characters like '-' by quoting them properly. For example: `history -s "-"` and `history -s '-'`. This tells bash to treat the '-' character as part of the argument string rather than an option.
  2. Step 2: By quoting the '-' character, you ensure that bash correctly interprets the '-s' option and stores or retrieves the shell history without errors.

🎯 Final Words

To summarize, the 'bash: history: - : invalid option' error can be resolved by using the '--' separator to avoid option interpretation or by quoting special characters in the argument string. By following these simple steps, you can ensure that your bash shell history is stored and retrieved correctly.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions