echo "Please enter your full name:"
read first last
echo $last
as long as the user input has a space between John & Doe then
$first=John
$last=Doe
echo "Please enter your full name:"
read first last
echo $last
as long as the user input has a space between John & Doe then
$first=John
$last=Doe
I don't know why you want first and last in the same string but here's an answer (there are many possible methods).
There are significant benefits to keeping the first and last separate (ie, if the person is a Jr, Sr. III etc) or has a hyphenated name or multiple sirnames...
#!/usr/bin/sh
echo "Enter your full name (i.e. first and last name)"
read name
echo "Hello Mr. `echo $name | awk '{print $NF}'`"
Good luck....
I don't know why it did not work with you. But for me, it works fine
Cat aw1.sh
echo "Please enter your full name:"
read name
echo $name | awk '{print"Hello Mr.", $2}'
pa9442 /ms/user/s/sibasha/tmp1 70$ sh aw1.sh
Please enter your full name:
Siba Nayak
Hello Mr. Nayak
Absolutely it's one of the best text processor AWK or GAWK whatever.
This is the correct sentences for your problem:
name="Mike Pathon"
echo $name | awk '{print "Hello Mr.", $2}'