[ Prev ] [ Index ] [ Next ]

Bash

Created Tuesday 15 April 2008 http://tldp.org/LDP/abs/html/string-manipulation.html

See Computer:Tips:Shellscripting

String Operators

string=abcABC123ABCabc
echo ${#string}	# 15
echo ${string:3}	# ABC123ABCabc (from 4th to end)
echo ${string:3:5}	# ABC12 (take 5 from 4th)
echo ${string#a*C}	# 123ABCabc (strip shortest match at beginning)
echo ${string##a*C}	# abc (strip longest match at beginning)
echo ${string%A*c}	# abcABC123 (strip shortest match at the end)
echo ${string%%A*c}	# abc (strip longest match at the end)
echo ${string/abc/def}	# xxxABC123ABCabc
echo ${string/#abc/xxx}	# xxxABC123ABCabc
echo ${string/#ABC/xxx}	# abcABC123ABCabc
echo ${string/%abc/xxx}	# abcABC123ABCxxx
echo ${string/%ABC/xxx}	# abcABC123ABCabc
echo ${string//abc/def}	# xxxABC123ABCxxx

Backlinks: :Computer:Software:Zsh