Echo command not working in Python Shell

python

#1

Any thoughts on why neither of these commands works in Python Shell?

  1. echo "hey"
  2. echo "hey" > hey.txt # Write hey to a new file

Result is: SyntaxError: invalid syntax


#2

The Python shell is not a POSIX shell like bash (the default shell on Cloud9). It’s instead a shell that only runs Python code. To see this in action, start the Python shell, type print("hi"), and hit enter, and you’ll see that it executes it as Python code. You can use any other Python, like import urllib, and you’ll see that it works as well.

TL;DR If you want to run any commands (like ls, cat, or echo), use bash (the normal shell), if you want to run Python code, use the Python shell (python2 or python3, depending on the language version you want).


#3

Bingo - that solved it, thank you!