I was doing some bash scripting a little while ago and while--8<-------
manipulating some text using some neat shortcuts I thought I'd share
in case anyone has a need to do just this;
I hope that this will help someone =)
I was doing some bash scripting a little while ago and while
manipulating some text using some neat shortcuts I thought I'd share
in case anyone has a need to do just this;
If you wanted to capitalise every word, you could do this;
```
$ stringArray=( $string )
$ echo ${stringArray[@]^}
This Is A String
```
If you wanted to capitalise every word, you could do this;
```
$ stringArray=( $string )
$ echo ${stringArray[@]^}
This Is A String
```
This one is interesting... why do we have to create a new variable;
or... what can't you just;
echo ${string[@]^}
I was doing some bash scripting a little while ago and while manipulating some text using some neat shortcuts I thought I'd share
in case anyone has a need to do just this;
This one is interesting... why do we have to create a new variable; or... what can't you just;
echo ${string[@]^}
Ah good question, the reason is because you need an array to be able to iterate over words in it, otherwise you'll just iterate over each character. That's why I made the array first out of the original string, it uses spaces as the separator, then you can iterate over each item in the array as intended.
Sysop: | CyberNix |
---|---|
Location: | London, UK |
Users: | 22 |
Nodes: | 10 (0 / 10) |
Uptime: | 37:29:37 |
Calls: | 903 |
Files: | 4,773 |
Messages: | 715,509 |