You are not logged in.

#3801 2024-12-12 06:49:32

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 8,408
Website

Re: Post your handy self made command line utilities

@HobbitJack is using a /bin/sh shebang, presumably to avoid the bash bloat, so they should probably read the "Case Conditional Construct" section of https://pubs.opengroup.org/onlinepubs/9 … hap02.html instead.

Bash == /bin/sh in Arch but most other distributions aren't so foolish.


Para todos todo, para nosotros nada

Offline

#3802 2024-12-12 09:04:33

HobbitJack
Member
From: Florida or Michigan
Registered: 2024-09-21
Posts: 10
Website

Re: Post your handy self made command line utilities

In this case it was mostly because this was bodged together several times (this is version 2 lol). Also something of force of Python habit, but this isn't Python. Next time I update it I'll want to merge the argument checking into a case statement, but if I recall I was just adding those ad hoc so whatever came out is what we got here.
I am at least aware of case statements, don't worry! =D
slides massive shell script monstrosities full of bloated case-esac used for data analysis under a rock

Last edited by HobbitJack (2024-12-12 09:06:58)


Astrophysicist and programmer. I like simple things.

Offline

#3803 2024-12-12 20:11:12

snakeroot
Member
Registered: 2012-10-06
Posts: 169

Re: Post your handy self made command line utilities

A seasonally-appropriate script that uses "find" to scan through FLAC files, find any with "Christmas" or "Xmas" in the file name and asks if the GENRE tag should add "Christmas" as a GENRE if it is absent.

#! /bin/bash
if [[ $# -eq 0 ]]; then
        /usr/bin/find . -regextype egrep -regex '.*(Xmas|Christmas).*\.flac' -exec $0 {} \;
else
        GENRE=$(/usr/bin/metaflac --show-tag=GENRE $1)
        if [[ ! $(echo $GENRE | /usr/bin/grep "Christmas") ]]; then
                echo "$1 does not contain Christmas in GENRE"
                read -p "Would you like to add it? [y/n]" answer
                if [[ $answer == y ]]; then
                        NEW_GENRE="$GENRE; Christmas"
                        NEW_GENRE=$(echo $NEW_GENRE | sed 's/GENRE=//')
                        echo "New GENRE is $NEW_GENRE"
                        /usr/bin/metaflac --preserve-modtime --remove-tag=GENRE --set-tag="GENRE=$NEW_GENRE" $1
                        /usr/bin/metaflac --show-tag=TITLE --show-tag=GENRE $1
                fi
        fi
fi

Offline

Board footer

Powered by FluxBB