Computing.Net > Forums > Unix > Last character in a string

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Last character in a string

Reply to Message Icon

Name: Anukta C.
Date: October 9, 2002 at 02:22:42 Pacific
OS: HP-UX
CPU/Ram: 256 MB
Comment:

Hi,
I have to find out whether the last character of a string is a "/" or not.
I have to accept a path from the stdin and find out whether it has a "/" in the end or not. If not, then append "/" to the end of the string. The logic runs thus:

echo "type the path of the file"
read dat_path
[find out the last character of the string]
[If the last character of the string is not "/" then append a "/" to the end of the string]

This is what I want the program to do.
I am having trouble with finding the last character of the string.
Any ideas?
-Anukta



Sponsored Link
Ads by Google

Response Number 1
Name: jimbo
Date: October 9, 2002 at 04:04:42 Pacific
Reply:

#! /bin/ksh
print "Enter a path: \c"
read PATH

case "$PATH" in
*/) echo "$PATH" ;;
*) echo "${PATH}/" ;;
esac


-jim


0

Response Number 2
Name: Anukta C.
Date: October 9, 2002 at 04:17:25 Pacific
Reply:

Thanks, that works !!!
-Anukta


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Last character in a string

Delete last character in a file www.computing.net/answers/unix/delete-last-character-in-a-file/5310.html

count the occurence of a char in a string www.computing.net/answers/unix/count-the-occurence-of-a-char-in-a-string/8516.html

detect a char in a string (ksh) www.computing.net/answers/unix/detect-a-char-in-a-string-ksh/4896.html