${string:position:length}
1 stringZ=abcABC123ABCabc 2 # 0123456789..... 3 # 0-based indexing. 4 5 echo ${stringZ:0} # abcABC123ABCabc 6 echo ${stringZ:1} # bcABC123ABCabc 7 echo ${stringZ:7} # 23ABCabc 8 9 echo ${stringZ:7:3} # 23A 10 # Three characters of substring.
[marc@kiriyamablevins ~]$ cat junk #!/bin/sh stringZ=abcABC123ABCabc echo ${#stringZ} # 15 echo `expr length $stringZ` # 15 echo `expr "$stringZ" : '.*'` # 15 echo ${stringZ:7:3} # 23A echo `expr substr $stringZ 1 2` # ab echo `expr substr $stringZ 4 3` # ABC echo `expr substr $stringZ ${#stringZ} 1` # c [marc@kiriyamablevins ~]$ ./junk 15 15 15 23A ab ABC c [marc@kiriyamablevins ~]$
$ x='this is a long string!' $ echo "${x:${#x}-1}" !
All trademarks, and forum posts in this site are property of their respective owner(s). FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc. Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding MembersPowered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.