troubleshooting Question

Getting the last character of a string with ksh

Avatar of YZlat
YZlatFlag for United States of America asked on
Unix OSShell Scripting
20 Comments1 Solution1048 ViewsLast Modified:
I need to capture the last character in a string, and if it equals to 's', I need to take one action, if not, then another.

I have

echo ${str:(-1)}

 ch= ${str:(-1)}

if [ ch == 's' ]



I get an error

${str:(-1)}: 0403-011 The specified substitution is not valid for this command.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 20 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 20 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros