STRING-LENGTH(1)
π STRING-LENGTH(1) π
okay so bestie, welcome to string-length from the fish-shell manual β yes it's a real section-1 page and yes it's about to be your new fave. it's literally just "how long is this string" energy but make it β¨preciseβ¨. sit down, grab a strawberry π, and let's get into it.
β¨ NAME β¨
string-length β print string lengths. that's it. that's the whole vibe check. π
πΈ SYNOPSIS πΈ
string length [-q | --quiet] [-V | --visible] [STRING ...]
look at her. iconic. the brackets are doing main character energy.
π¦ DESCRIPTION π¦
so string length reports the length of each string argument in characters. one number per string, no cap.
Exit status: 0 if at least one non-empty STRING was given, or 1 otherwise. so basically it tells you "yeah something's there" or "nope, empty bestie" π
here's the two flags, no notes:
-q,--quietβ quiet mode, she's not announcing anything, just give me the status-V,--visibleβ measure the visible width instead of raw character count. this is the queen flag honestly π
and like. what does --visible actually do, you ask? glad you asked babe, because it's giving nuance:
- it discounts escape sequences fish knows about β so all that colour-code noise doesn't get counted β¨
- it accounts for
$fish_emoji_widthand$fish_ambiguous_widthβ yes those are real variables, yes they matter π - it counts each line on its own when they're separated by
\nβ separate lines, separate widths, periodt - with a carriage return (
\r) it counts only the widest stretch on a line β because that's what actually survives on screen - the whole intent is to measure the number of columns the STRING would occupy in the current terminal π₯οΈπ
bestie note:-qand-Vare the two options. that's the list. don't go looking for more, there aren't more. π«Ά
π EXAMPLES π
okay this is the fun part, let's go:
>_ string length 'hello, world'
12
twelve. slay. simple as that π
>_ set str foo
>_ string length -q $str; echo $status
0
# Equivalent to test -n "$str"
see that # Equivalent to test -n "$str"? that's the whole trick β -q plus $status is basically a test -n. iykyk π§
>_ string length --visible (set_color red)foobar
# the set_color is discounted, so this is the width of "foobar"
6
the set_color gets discounted (as the comment says, fr fr), so what's left is just the width of "foobar" β 6. the escape codes are NOT invited to the measurement party π«π
>_ string length --visible ππππ
# depending on $fish_emoji_width, this is either 4 or 8
# in new terminals it should be
8
four fishies, but the width depends on $fish_emoji_width β either 4 or 8, and in new terminals it should be 8. emoji math is real and it's coming for us ππ₯
>_ string length --visible abcdef\r123
# this displays as "123def", so the width is 6
6
the \r carriage return situation: it displays as "123def", so width is 6. the \r goes back to the start and overwrites β and only the widest stretch counts. literally erasing herself, main character behaviour π
>_ string length --visible a\nbc
# counts "a" and "bc" as separate lines, so it prints width for each
1
2
two lines, two numbers: 1 then 2. each line gets its own width, one per line, in order. no merging, no combining, we respect boundaries here π«Ά
π Copyright π
fish-shell developers
and that's the page bestie!! π you now know string length better than most people know their own passwords. go measure something. go be iconic. π¦β¨
πΈ sign-off szn: this was from fish-shell, version 4.9, dated Sep 08, 2026 β so go forth and <rainbow>slay</rainbow> responsibly, mwah ππ
π¦ where this page comes from
- arch rolling: fish 4.9.3-1 Β· GPL-2.0-only AND BSD-3-Clause AND ISC AND MIT AND PSF-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms