PDA

View Full Version : UNIX Korn typeset, if loop questions




SnowLeopard2008
Apr 26, 2009, 02:13 PM
This is my homework, but I only need help on a few things. I'm writing a script to convert user inputted variables to all lowercase and then all uppercase. And then comparing the variables using the if loop. Here's my script:

#!/bin/ksh
# He Chen
# Assignment 10, a10b, Apr 25
# Greet user in Korn shell

print "Welcome, please enter your first and last name."
read first last
#print $first $last

# convert names to lowercase
set typeset -l first="$first"
set typeset -l last="$last"
print $first $last

if [[ ${first1} = tom && ${last1} = jones ]] then
print "Welcome, Tom Jones."

# convert names to uppercase
set typeset -u $first $last

elif [[ ${first} != tom && ${last} != jones ]] then
print "Are you happy today, $first $last?"
fi


When I execute the script, the typeset command doesn't work (see the print $first $last) and the if loops won't work. Any help? I've search my textbook, and the powerpoints from my teacher. None of which helped.

EDIT: I'm not sure if this forum is the right place, but it's the best match for my question.



LtRammstein
Apr 26, 2009, 09:08 PM
Try here:

http://www.atnf.csiro.au/computing/software/sol2docs/ipe-help/dbx/dbx88mmm.html

That should put you on the right track. Since I don't know ksh, a quick Google search on "ksh typeset" has given me quite a few hits.

SnowLeopard2008
Apr 27, 2009, 02:13 AM
Thanks I got it. Just had the wrong syntax. Thanks!

zmttoxics
Apr 27, 2009, 02:23 PM
Welcome to KSH. Just a note for you, thats called an "if statement", there is no looping involved there. I recommend you read the differences between KSH88 and KSH93 if you are just starting scripting with KSH. 93 is more compatible with BASH scripting, while 88 is found on more "secure" / legacy systems like Solaris 8-10.

Good luck!