I am doing a bash script and I want to display the characters of a variable ($VAR). What I want the script to do is (pseudo-code) :
String var = "Hello";
for (int i = 0; i < var.length(); i++) {
System.out.println(var.substring(i, i+1));
}
The size of the variable can change, one time it can be 5 characters and the next time 6 for example.
Thank you for you help!
Michaël
Here’s a, hopefully quite close, translation.
Illustrates a few bash concepts.
${#var}gives the number of characters in variable${var}${var:x:y}gives a substring of characters of${var}starting at positionx, lengthy