Strange infinite loop by a very specific syntax error in PS1
From:
smart . outfit080
Subject:
Strange infinite loop by a very specific syntax error in PS1
Date:
Thu, 07 Aug 2025 07:50:28 +0000
Hello,
I have encountered a situation where a specific syntax issue (trying to use a
floating point number in variable string slicing) in PS1 causes it to become a
CPU-hogging infinite error loop and never actually display the PS1 prompt. To
reproduce:
1. Run a clean shell:
env -i bash --rcfile /dev/null
2. Run this:
PS1+='${-:$((.))}'
3. Now it loops the following error message:
bash: .: syntax error: operand expected (error token is ".")
which seemingly can't be stopped unless you close the terminal emulator window.
This doesn't seem to occur in other types of syntax error, like a simple
missing parenthesis:
bash-5.2$ PS1+='$(:'
bash: command substitution: line 3: unexpected EOF while looking for matching
`)'
I don't understand this behavior. Why does such a loop happen? Is this a bug?