Need Help.

Hello

I am new in linux scripting. I have problems with this script:

Why "wa" is not equal to "user" when I am login in my terminal like user?

How to get wa equal to "user"?

Thanks

Please put code inside

```text
 ... 
```

tags.

if [ "$wa" = user ]; then

From The UNIX and Linux Forums - Forum Rules

user should be in quotes.

if [ "$wa" = "user" ]

Nothing happens.

#!/bin/bash
wa=$(whoami)
if ["$wa"= user]; then
echo "I am: $wa"
else 
echo "Who are you?"
fi

Result:

user@user-desk:~$ ./sc.sh
./sc.sh: line 3: [user=: command not found
Who are you?
user@user-desk:~$ 

Any ideas?

Hi.

First, user doesn't have to be in quotes. It's a literal string.

Second, if you'd looked at the original solution given you'd see that spaces are important here.

if [ "$wa" = user ]; then

Not

if ["$wa"= user]; then
if [ ${user:-NULL} = user ];then 

Just in case :cool:

Not sure that's neccessary, if you use quotes, but OK :wink:

Thanks!!!