STRING-SUB(1)

πŸ¦‹ STRING-SUB(1) β€” the string sub page, bestie edition πŸ¦‹

okay so real talk, this is a page from fish-shell, and it's all about string sub. it's short, it's iconic, and honestly? it ate. let's get into it πŸ’…


✨ NAME ✨

string-sub β€” extract substrings πŸŽ€

like, you got a string? you want a smaller string out of it? bestie, this is the tool. periodt.


✨ SYNOPSIS ✨

string sub [(-s | --start) START] [(-e | --end) END] [(-l | --length) LENGTH]
           [-q | --quiet] [STRING ...]

that's the whole vibe up there ^^ no cap, that's the entire shape of it. notice the -q | --quiet sitting there all mysterious πŸ‘€ β€” it's literally in the synopsis, so it's a real option, and it's listed below with the others fr fr.


✨ DESCRIPTION ✨

string sub prints a substring of each STRING argument. like, per argument. it does the thing for each one. 🌸

where does it start, where does it end 🫢

you tell it where the substring starts and/or ends using -s/--start or -e/--end, followed by a 1-based index value. yes, 1-based. the first character is 1, not 0. that's the whole system, don't fight it πŸ’€

  • positive index values are relative to the start of the string
  • negative index values are relative to the end of the string

the default start value is 1 β€” so if you don't say anything, it starts at the very beginning like the main character it is πŸ‘‘

how long is it πŸ‘‘

the length of the substring can be specified with -l or --length. and if the length or end is not specified, the substring continues all the way to the end of each STRING. it just keeps going. no stop sign. πŸ¦‹

the flags, one by one πŸ’–

  • -s, --start START β€” where the substring begins. 1-based index. positive = from the start of the string, negative = from the end of the string. default is 1.
  • -e, --end END β€” where the substring ends. also a 1-based index value, same positive/negative rules as above.
  • -l, --length LENGTH β€” how long the substring is. remember: --length is mutually exclusive with --end β€” you pick one, you don't get both, that's the rule πŸ”₯
  • -q, --quiet β€” listed in the synopsis up there with the rest of the squad 😌 (this page doesn't describe its behaviour, so we're not gonna make stuff up about it, iykyk)
⚠️ heads up bestie: --length is mutually exclusive with --end. that's not a suggestion, that's the deal. don't come for both at once 🫢

exit status πŸ’€

  • 0 β€” if at least one substring operation was performed (we did it, we slayed)
  • 1 β€” otherwise (nothing happened, sad)

✨ EXAMPLES ✨

okay this is the fun part, watch this:

>_ string sub --length 2 abcde
ab

two characters, from the front. ab. iconic. 🌟

>_ string sub -s 2 -l 2 abcde
bc

start at 2, grab 2. bc. chef's kiss πŸŽ€

>_ string sub --start=-2 abcde
de

negative start! from the end! de. the way that works 😭

>_ string sub --end=3 abcde
abc

end at 3, and since there's no start it defaults to 1. abc. clean. ✨

>_ string sub -e -1 abcde
abcd

end at -1, i.e. one from the end. abcd. literally the whole thing minus the last letter πŸ¦‹

>_ string sub -s 2 -e -1 abcde
bcd

start at 2, end at -1. bcd. look at her go πŸ’œ

>_ string sub -s -3 -e -2 abcde
c

negative start AND negative end. c. one single lowercase c. and honestly? she's the moment. πŸ‘‘


fish-shell developers β€” that's the copyright line, keep it safe, credit the makers 🫢


and that's the page!! no cap, you're now a string sub girlie. go slice some strings, bestie πŸŒˆπŸ’…

⭐ this was STRING-SUB(1) from fish-shell, version 4.9, dated Sep 08, 2026 β€” mwah, bye πŸŽ€

πŸ“¦ 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