this post was submitted on 07 Feb 2025
4 points (83.3% liked)

Linux

49701 readers
957 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

Little Update: Just added an exit command after the help.

Here is another little script that nobody asked for. There are multiple ways to accomplish this, but I always forget how or which is the best way. Use tr? Or sed? When can I use the more efficient Bash substitutions instead, which are Bash integrated functionality of variables that saves me some extra calls. Also most solutions to title case will compress all spaces to single space after a word; not this "title" solution, which respects the spaces.

Use this like you would use grep or tr, which get input from stdin and output to stdout. There are no special options, only mode names without dashes. Multiple modes can be combined, but there is actually no reason to do so at the moment.

Example:

echo "Hello World, this is an EXAMPLE." | tocase toggle upper1

tocase:

(Note, this Beehaw instance always replaces some characters and makes the below script unusable. Copy it from the linked script instead.)

#!/usr/bin/env bash

if [ "${#}" -eq 0 ] ; then
    cat << EOF
usage: tocase option...

options:
    upper       all uppercase
    upper1      upper first character

    lower       all lowercase
    lower1      lower first character

    toggle      swap uppercase and lowercase
    toggle1     swap upper and lower of first character

    title       upper first character and lower rest of each word

examples:
    echo "Hello World, this is an EXAMPLE." | tocase toggle upper1
EOF
exit 0
fi

while IFS= read -r stdin ; do
    for argument in "${@}" ; do
        case "${argument}" in
        upper) stdin="${stdin^^}" ;;
        upper1) stdin="${stdin^}" ;;
        lower) stdin="${stdin,,}" ;;
        lower1) stdin="${stdin,}" ;;
        toggle) stdin="${stdin~~}" ;;
        toggle1) stdin="${stdin~}" ;;
        title)
            # Note: Many other solutions other than this sed command do not 
            # work on each word.
            stdin="$(sed -r 's/\<./\U&/g' <<<"${stdin}")"
            ;;
        esac
    done

    printf "%s\n" "${stdin}"
done
no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here