In your question, you imply that you're not quoting the line at all; that's clearly wrong, because then the space would separate the argument assignment "PS1=[\u@\h" from the command "\W]\$". Please realise that every character is important.
Anyway, what you're probably doing is using double quotes (") rather than single ones ('). They behave very different when it comes to the shell interpreting what you typed. With double quotes, it will try to do clever things with the sequences of backslash/some-character. For this assignment, since there's nothing special about \u, \h, and \W, they're left untouched; square brackets can have special meanings in various places, but not in this case, so they're also left in place; but since a $
has a variety of meanings, all of them special, the \$
sequence is interpreted as "ignore the specialness of the dollar sign, and just leave it there", and that sequence is replaced with a no-further-parsed single dollar sign. The result of all of that is assigned to PS1
, and since there's a literal dollar sign, and not the magic \$
sequence when the shell constructs the actual prompt, you just get the dollar sign, and not the effective-user-dependent character. The actual parsing is a bit more complicated, but that's the gist of it for this particular example.
What you typed: PS1="[\u@\h \W]\$ "
What the shell assigned: PS1 <- "[\u@\h \W]$ "
What you wanted: PS1 <- "[\u@\h \W]\$ "
What you should type: PS1='[\u@\h \W]\$ '
What you should do next: Read something like this tutorial to learn more about shell quoting.
PS1=[\u@\h \W]\$
returns-bash: W]$: command not found
.PS1="[\u@\h \W]\$"
.