ksh는 아주 기본적인 쉘이어서 라이브러리는 커녕
기본적인 스트링 함수조차 찾기 어렵다.

제한적인 기능 속에서도 도움이 되는


The pattern in the following uses the same wildcards as for filename matching.

${#var}
    $var의 길이를 리턴
${var%pattern}
    removes the shortest suffix of $var patching pattern
${var%%pattern}
    removes the longest suffix of $var patching pattern
${var#pattern}
    removes the shortest prefix of $var patching pattern
${var##pattern}
    removes the longest prefix of $var patching pattern

Numeric variables

$(( integer expression ))
    The $(( ... )) construction interprets the contents as an arithmetic expression (integer only). Variables are referenced by name without the "$". Most of the arithmetic syntax of the 'C' language is supported, including bit manipulations (*,/,+,-,|,&,<<,>>. Use parentheses for changing precedence).

Examples
datapath=/data/public/project/trials/set1/datafile.dat

filename=${datapath##*/}
    filename is set to "datafile.dat" since the longest prefix pattern matching "*/" is the leading directory path (compare basename)
path=${datapath%/*}
    path is set to "/data/public/project/trials/set1" since the shortest suffix pattern matching "/*" is the filename in the last directory (compare dirname)

i=$((i+1))
    often used in while loops
Posted by in0de
,