Question:
Whenever I type a simple print function into the console, it gives me an error message: “bash: syntax error near unexpected token”.
Repl link:
Testing in C# - Replit
code snippet
```Console.WriteLine("example");
Question:
Whenever I type a simple print function into the console, it gives me an error message: “bash: syntax error near unexpected token”.
Repl link:
Testing in C# - Replit
code snippet
```Console.WriteLine("example");
I just ran your code and everything is fine.
Are you using the “Run” button?
(Remember that you can’t run C# code directly in a bash shell)
Just to clarify:
Shell (or bash), is an interpreter. Interpreter reads commands entered by the user and executes them. Bash is designed to understand commands written in the bash scripting language.
C#, is a statically-typed, compiled language. It has a very different syntax from bash.
So when you try to run C# code directly in a bash, the bash tries to interpret the C# code as if it were bash commands, and since the syntax and commands of C# are entirely different from bash, bash will say “dafugg am I reading” and gives you a syntax error.
Previously, I was using the Run Button, however, I have noticed that the issue was that every time I entered a command into the console the program was already over therefore accidentally compiling the C# code into bash.
thanks for the clarification @WindLother
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.