How do I a obtain particular length of a string variable using a bash shell script?
-
Usage is ${name:start:length}
If the length is no specified, it uses the rest of value.
declare -A MyBucketList MyBucketList=([1]="The rain in Spain stays mainly on the plain" [2]="Go to Mars" [3]="Climb Mount Everest") echo ${MyBucketList[1]:5}
Running the script gives the following results.
The ra
is excluded. Remember the count starts at zero.$ ./associative_array.sh in in Spain stays mainly on the plain
Change line 3 to
echo ${MyBucketList[1]:5:10}
and run the script again. Start fromcount 5
in the value, and thelength of 10
$ ./associative_array.sh in in Spai
© Lightnetics 2024