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,--startSTART β where the substring begins. 1-based index. positive = from the start of the string, negative = from the end of the string. default is1.-e,--endEND β where the substring ends. also a 1-based index value, same positive/negative rules as above.-l,--lengthLENGTH β how long the substring is. remember:--lengthis 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:--lengthis 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. π
β¨ Copyright β¨
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