hi i would like to know how to replace the 2nd/3rd... character in a string without knowing what value it holds.
replacing characters is string
Collapse
X
-
get the first character of the string (we want to replace 2nd and 3rd character so the 1st character must rewrite)
Code:expr substr string 1 1
write 'TR' as 2nd and 3rd characters
write the rest of the string (character from 4th ). if we don't know what is the the lenght of the string we can use length as here.Code:echo -n TR
` ` means treat the string inside as a command and execute it.Code:expr substr string 4 `expr length\ string`
I advise you to read manual for exec commandComment
Comment