[ Prev ] [ Index ] [ Next ]

Zsh

Created Tuesday 15 April 2008

See http://zsh.sourceforge.net/Doc/Release/zsh_13.html#SEC54 See http://zsh.sourceforge.net/Doc/Release/zsh_14.html See Bash See Computer:Tips:Shellscripting

String Operators

${=var}	# Force splitting variable
string=abcABC123ABCabc
echo ${+string}		# 1 ($string is defined)
echo ${+foovar}		# 0 ($oovar is not defined)
echo ${#string}		# 15
echo ${string[2]}		# b (2nd)
echo ${string[-3]}		# c (3rd from the end)
echo ${string[3,5]}		# cAB (from 3 to 5 included)
echo ${string[5,-1]}	# BC1231BCabc (from 5th to the end)
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)

No backlinks to this page.