Friday 16 August 2013

how to write only a specific range of characters into a variable, and stuff.

Specify range of characters:

variablea="noyesno"
variableb=${variablea:2:3}
echo $variableb

this will pring "yes"


Skip first and last characters. Independent of string length:

variablea="xsomethingx"
variableb="${variablea:1:${#variablea}-2}"
echo $variableb

this will print "something"

No comments:

Post a Comment