I am getting an error when I try and run my assignment.
#!/bin/bash
## Assignment 2
echo Please enter a User Name:
read u
if [ $u!="root"]; then
echo Searching for Username!
grep $u /etc/passwd|sed 's/$u/hidden/gi'
elif [ $u!="toor"]; then
echo Root is NOT allowed.
else
echo Toor is definetely NOT allowed.
fi
Output:
Please enter a User Name:
user1
./assign2.sh: line 6: [bthiessen: command not found
./assign2.sh: line 9: [bthiessen: command not found
Toor is definetely NOT allowed.
What is wrong with my if statements?
Try that :
problems founds :
[ $u!="root"]need spaces around!="quotes, not simple'note :
[[is a bash keyword similar to (but more powerful than) the[command. See http://mywiki.wooledge.org/BashFAQ/031 and http://mywiki.wooledge.org/BashGuide/TestsAndConditionals . Unless you’re writing for POSIX sh, we recommend[[Learn the difference between
'and"and `. See http://mywiki.wooledge.org/Quotes and http://wiki.bash-hackers.org/syntax/words