String length: Difference between revisions
Content added Content deleted
(→Joy: add) |
m (→{{header|UNIX Shell}}: Add note about bytes vs characters in implementations) |
||
Line 3,612: | Line 3,612: | ||
=={{header|UNIX Shell}}== |
=={{header|UNIX Shell}}== |
||
===Byte |
====Byte length via external utility:==== |
||
====With external utility:==== |
|||
{{works with|Bourne Shell}} |
{{works with|Bourne Shell}} |
||
Line 3,621: | Line 3,620: | ||
====With [[Unix|SUSv3]] parameter expansion modifier:==== |
====With [[Unix|SUSv3]] parameter expansion modifier:==== |
||
This returns the byte count in ash/dash, but the character count in bash, ksh, and zsh: |
|||
{{works with|Almquist SHell}} |
{{works with|Almquist SHell}} |
||
{{works with|Bourne Again SHell |
{{works with|Bourne Again SHell}} |
||
{{works with| |
{{works with|Korn Shell|93}} |
||
{{works with|Z SHell}} |
{{works with|Z SHell}} |
||
<syntaxhighlight lang="bash">string='Hello, world!' |
<syntaxhighlight lang="bash">string='Hello, world!' |
||
length= |
length=${#string} |
||
echo $length # if you want it printed to the terminal</syntaxhighlight> |
echo $length # if you want it printed to the terminal</syntaxhighlight> |
||