strstr() in Bash: Check if a String Contains a Substring
Test whether a string contains a substring in pure Bash, or get the rest of the string from the first match the way PHP's strstr() does.
Archive
Test whether a string contains a substring in pure Bash, or get the rest of the string from the first match the way PHP's strstr() does.
Get the directory part of a path in pure Bash, matching coreutils dirname on trailing slashes, bare names and the root, without starting a process.
A yes/no confirmation prompt for Bash scripts that accepts any case, has an optional default and handles cron, pipes and EOF without looping forever.
Get the file name from a path with parameter expansion, matching coreutils basename on trailing slashes, "/" and suffixes, without starting a process.
A ucfirst() for Bash 4+ and macOS's Bash 3.2, what "first character" really means, and how to get "Hello" from "hELLO" or " hello".
A ucwords() for Bash that works word by word instead of char by char, preserves all whitespace, and lets you decide what counts as a word boundary.
Run a command silently and test only its exit status. Why "$@" beats storing a command in a string, and what to use for pipelines.
Delete every occurrence of a substring with one Bash parameter expansion, no sed or tr needed, and the quoting mistakes that make it go wrong.
lcfirst() in Bash with ${var,} and a Bash 3.2 fallback, used for PascalCase to camelCase, plus a fix for names that begin with an acronym.
A str_repeat() for Bash that stays fast at millions of copies, why the common printf trick slows down, and the two bugs in the 2009 version.