Simple scripting.

echo "what is your username?"
read username
echo $username
echo /home/$username
$backup="backup"
$restore="restore"
#
#
if [$username == ""]
then
echo "No username provided"
else
echo "hi $username would you like to backup or restore?"
read userrequest
echo $userrequest
        if [$userrequest = $backup]
        then
        echo "You picked backup"
        elif [$userrequest = $restore]
        then
        echo "You picked restore"
        else
        echo "Choose something"
        fi
fi

Hey guys, complete newbie here at linux scripting. My aim is to create a backup utility using linux scripting. Below is what I have started on so far but I'm having a few issues:

How do I assign the words "backup" and "restore" to variables called $backup and $restore and then check in the below part of the code to see if what the user entered was in fact the word "backup" or "restore"?

echo "hi $username would you like to backup or restore?"
read userrequest
echo $userrequest
        if [$userrequest = $backup]
        then
        echo "You picked backup"
        elif [$userrequest = $restore]
        then
        echo "You picked restore"
        else
        echo "Choose something"
        fi
fi

Just this bit that's bothering me so far. Thanks for any help :slight_smile:

Ewan

assign a value to a variable : "="

variable=value

I think this code will serve your purpose:

echo "what is your username?"
read username
echo "Hello $username"
backup="backup"
restore="restore"
if [[ $username == "" ]]
then
echo "No username provided"
exit 1
else
echo /home/$username
echo "hi $username would you like to backup or restore?"
read userrequest
echo $userrequest
        if [ $userrequest = $backup ]
        then
        echo "You picked backup"
        elif [ $userrequest = $restore ] 
        then
        echo "You picked restore"
        else
        echo "Choose something"
        fi
fi

Thanks a lot :b::smiley:

You are Welcome!:slight_smile: