Strings are quite basic in any scripting or programming languages. If a journey to a thousand miles starts with a single step, in the programming world the journey starts with a string called “Hello World” and beyond “Hello World” pseudocode and algorithm will keep the journey going. Strings in scripting or programming are just group of characters. So, if string is a group of characters then it can be slice by character or a sub-string can be taken from the string. To slice a string in Bash, a syntax which is part of the Bash library can be used. Syntax is: ${string_to_be_sliced:slice_start_position:slice_end_position} Example string: slicethestring=“Hello Algorithm World” The string is stored in a variable: slicethestring To get the sub-string “Algorithm World”. Code will be: echo ${slicethestring:6:23} #start the slice at position 6 till position 23 Another way to slice the string from a specified start position till the end; is to tell Bash the star...
Make the world a better place by sharing knowledge, ideas and anything that you can give that comes from the heart.