Korn Shell Substring
Posted on 2006-06-14
In a korn shell script I have a directory name in a variable $TARGET_DIR
e.g. "/home/username" or "/home/username/"
I want to ensure that the string is in the second format (with the trailing slash)
How can this be done with ksh?
I was going to do it something like this:
#get the length of the string
#Get the last character in the string
LST_CHR=substr($TARGET_DIR, $STR_LEN - 1) ??? This part is made up and not a real command.
#If the last char isn't "/" then add it to the end
if [ $LST_CHR != '/' ]
Get it? Since I'm obviously new to ksh if you have any little syntax corrections for the rest of my code that would be helpful too.