0

I am using Python with the command-line option -c. Printing some strings works:

python -c "print('foo')" foo 

but printing an exclamation mark triggers some bash-related error:

python -c "print('!')" -bash: !': event not found 

Can anyone explain what I am doing wrong? I cannot understand why python/bash could not parse this very simple example.

3
  • 2
    With your code surrounded by double quotes ", it is first expanded by your shell. With single quotes ', the shell will take the argument as literal string: python -c 'print("!")' (using double quotes inside python to avoid quoting quotes) Commented Oct 30, 2023 at 10:19
  • @FlashThunder We're talking about double quotes and shell expansion, not backticks and execution. Commented Oct 30, 2023 at 10:23
  • @FlashThunder Thank you. It probably works fine for everyone. Commented Oct 30, 2023 at 10:47

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.