Bash Programming : Check typed name is a valid $USER or not

I tried it hardly….Here you have to maintain the syntax

if[expression]
then
echo `expr “”Hello Name`
fi

and this conditional

if [ “foo” = “foo” ]; then
echo expression evaluated as true
fi

or the same things can be written as

if[ “foo” = “foo” ]
then
echo `expr “Hello !”`
fi

if..then..else in bash

if [ “zaki” = “live” ]
then
echo `expr “True !”
else echo `expr “False!”`

conditional with variables
t1=”zaki”
t2=”live”
if [ “$t1” = “t2” ]
then
echo `expr “True” `
else
echo `expr “False”`
fi #you have to end with this if you started with if

echo `expr "What's your name?"`
read name
if [ "$name" = "$USER" ] 
then
 echo `expr "Hello $name"`
else
 echo `expr "You are not valid user!"`
fi

Reference: http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-6.html#ss6.1
http://ryanstutorials.net/bash-scripting-tutorial/bash-if-statements.php

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *