String Manipulation

KSH string operations

KSH string length and substring

KSH string length, substring, and pattern matching

#!/bin/ksh
text="Hello World"

# String length
print "Length: ${#text}"

# Substring extraction
print "First 5 chars: ${text%?????}"
print "From position 6: ${text#?????}"

# Pattern matching
if [[ $text == *"World"* ]]; then
    print "Contains 'World'"
fi
KSH string replacement

KSH string replacement operations

#!/bin/ksh
text="Hello World Hello"

# Replace first occurrence
print "Replace first: ${text/Hello/Hi}"

# Replace all occurrences
print "Replace all: ${text//Hello/Hi}"

# Replace at beginning
print "Replace start: ${text/#Hello/Hi}"

# Replace at end
print "Replace end: ${text/%Hello/Hi}"