Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
35
rated 0 times [  35] [ 0]  / answers: 1 / hits: 7460  / 1 Year ago, mon, march 27, 2023, 8:27:28

Please look at these commands:



$ notify-send SYNC TIME!
$ notify-send 'SYNC TIME!'
$ notify-send "SYNC TIME!"
bash: !": event not found
$


The first two commands produce a notification bubble as expected. The third gives the error shown.



and



$ echo SYNC TIME!
SYNC TIME!
$ echo 'SYNC TIME!'
SYNC TIME!
$ echo "SYNC TIME!"
bash: !": event not found
$


Here as well, the echo works for first two commands but not in the third.



More problems here (although I was not planning on using this): both notify-send "SYNC!TIME" and echo "SYNC!TIME" give bash: !TIME": event not found.



But both notify-send and echo work with "SYNC! TIME"



Can someone please explain why the bash: !": event not found error appears?


More From » bash

 Answers
1

! is the default history expansion character in Bash, see the section "HISTORY EXPANSION" in the Bash manpage




  • History expansion doesn't take place if the ! is enclosed by single quotes, as in



    notify-send 'SYNC TIME!'

  • History expansion doesn't take place if the ! is followed by a space, tab, newline, carriage return, or =, as in



    notify-send SYNC TIME!

  • History expansion does take place in



    echo "SYNC TIME!"


    So you'll get an error if there isn't a command starting with " in your history



[#26489] Wednesday, March 29, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
enytidge

Total Points: 169
Total Questions: 105
Total Answers: 107

Location: Papua New Guinea
Member since Tue, Aug 24, 2021
3 Years ago
enytidge questions
Tue, Feb 28, 23, 15:26, 1 Year ago
Sun, Jan 1, 23, 19:36, 1 Year ago
Sun, Oct 24, 21, 07:30, 3 Years ago
Wed, Nov 9, 22, 22:02, 2 Years ago
;