Need Help.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need Help.
# 1  
Old 10-25-2009
Need Help.

Hello

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

Quote:
#!/bin/bash
wa=$(whoami)
if [$wa="user"]; then
echo "I am: $wa"
else
echo "Who are you?"
fi
Why "wa" is not equal to "user" when I am login in my terminal like user?

How to get wa equal to "user"?

Thanks
# 2  
Old 10-25-2009
Quote:
Originally Posted by niki22
Hello

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

Please put code inside [code] ... [/code] tags.
Quote:
Code:
#!/bin/bash
wa=$(whoami)
if [$wa="user"]; then


Code:
if [ "$wa" = user ]; then

# 3  
Old 10-25-2009
From The UNIX and Linux Forums - Forum Rules
Quote:
(11) Post questions with descriptive subjects. For example, do not post questions with subjects like "Help Me!", "Urgent!!" or "Doubt". Post subjects like "Execution Problems with Cron" or "Help with Backup Shell Script".
# 4  
Old 10-25-2009
user should be in quotes.

Code:
if [ "$wa" = "user" ]

# 5  
Old 10-25-2009
Nothing happens.

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

Result:

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

Any ideas?
# 6  
Old 10-25-2009
Quote:
Originally Posted by niki22
Nothing happens.

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

Result:

Code:
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.

Code:
if [ "$wa" = user ]; then

Not
Code:
if ["$wa"= user]; then

# 7  
Old 10-25-2009
Code:
if [ ${user:-NULL} = user ];then

Just in case Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question