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_width and $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: -q and -V are 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 🫢


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