From f28d694879239d5d9c319185a278236d317a49b6 Mon Sep 17 00:00:00 2001 From: zachir Date: Sat, 30 Aug 2025 01:09:18 -0500 Subject: Make sh scrips POSIX compliant Using shellcheck, I went through all of them to make them standards compliant. I also tested as many as I could. --- tagmp3 | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'tagmp3') diff --git a/tagmp3 b/tagmp3 index c6bfe4f..3474a90 100755 --- a/tagmp3 +++ b/tagmp3 @@ -1,9 +1,9 @@ #!/bin/sh -FILENAME=`echo $@ | rev | cut -d' ' -f1 | rev` +FILENAME="$(echo "$*" | rev | cut -d' ' -f1 | rev)" # check for flags -for i in $@; do +for i; do case "$i" in "-"*) unset ARTISTFLAG ALBUMFLAG SONGFLAG ;; @@ -32,50 +32,50 @@ for i in $@; do esac done -ARTISTNAME=`echo $ARTISTNAME | sed 's/^ //'` -ALBUMNAME=`echo $ALBUMNAME | sed 's/^ //'` -SONGNAME=`echo $SONGNAME | sed 's/^ //'` +ARTISTNAME="$(echo "$ARTISTNAME" | sed 's/^ //')" +ALBUMNAME="$(echo "$ALBUMNAME" | sed 's/^ //')" +SONGNAME="$(echo "$SONGNAME" | sed 's/^ //')" -echo "\n$FILENAME\n" +printf "\n%s\n\n" "$FILENAME" # guess artist name from title -ARTISTNAME_GUESS=`echo "$FILENAME" | cut -d'-' -f1 | sed 's/_*$//;s/_/ /g'` +ARTISTNAME_GUESS="$(echo "$FILENAME" | cut -d'-' -f1 | sed 's/_*$//;s/_/ /g')" # guess album name from title -ALBUMNAME_GUESS=`echo "$FILENAME" | cut -d'-' -f2 | sed 's/^_*//;s/_*$//;s/_/ /g'` +ALBUMNAME_GUESS="$(echo "$FILENAME" | cut -d'-' -f2 | sed 's/^_*//;s/_*$//;s/_/ /g')" # guess track number from title -TRACKNUMBER_GUESS=`echo "$FILENAME" | cut -d'-' -f3 | cut -d'_' -f2` +TRACKNUMBER_GUESS="$(echo "$FILENAME" | cut -d'-' -f3 | cut -d'_' -f2)" # guess song name from title -SONGNAME_GUESS=`echo "$FILENAME" | cut -d'-' -f3 | sed 's/^_[0-9]*_//;s/_/ /g;s/\.mp3$//;s/\.flac$//'` +SONGNAME_GUESS="$(echo "$FILENAME" | cut -d'-' -f3 | sed 's/^_[0-9]*_//;s/_/ /g;s/\.mp3$//;s/\.flac$//')" # get the artist name input -[ -z "$ARTISTNAME" ] && echo "Input the Artist name:\nGuessed name is $ARTISTNAME_GUESS" && read ARTISTNAME +[ -z "$ARTISTNAME" ] && printf "Input the Artist name:\nGuessed name is %s" "$ARTISTNAME_GUESS" && read -r ARTISTNAME [ -z "$ARTISTNAME" ] && ARTISTNAME="$ARTISTNAME_GUESS" echo "$ARTISTNAME" # get the album name input -[ -z "$ALBUMNAME" ] && printf "Input the Album name:\nGuessed name is %s" "$ALBUMNAME_GUESS" && read ALBUMNAME +[ -z "$ALBUMNAME" ] && printf "Input the Album name:\nGuessed name is %s" "$ALBUMNAME_GUESS" && read -r ALBUMNAME [ -z "$ALBUMNAME" ] && ALBUMNAME="$ALBUMNAME_GUESS" echo "$ALBUMNAME" # get the track number input -[ -z "$TRACKNUMBER" ] && printf "Input the track number:\nGuessed number is %s" "$TRACKNUMBER_GUESS" && read TRACKNUMBER +[ -z "$TRACKNUMBER" ] && printf "Input the track number:\nGuessed number is %s" "$TRACKNUMBER_GUESS" && read -r TRACKNUMBER [ -z "$TRACKNUMBER" ] && TRACKNUMBER="$TRACKNUMBER_GUESS" echo "$TRACKNUMBER" # get the song name input -[ -z "$SONGNAME" ] && printf "Input the song name:\nGuessed name is %s" "$SONGNAME_GUESS" && read SONGNAME +[ -z "$SONGNAME" ] && printf "Input the song name:\nGuessed name is %s" "$SONGNAME_GUESS" && read -r SONGNAME [ -z "$SONGNAME" ] && SONGNAME="$SONGNAME_GUESS" echo "$SONGNAME" # get the year input -[ -z "$YEARNUMBER" ] && echo "Input the year number:" && read YEARNUMBER -[ ! -z "$YEARNUMBER" ] && mid3v2 -y "$YEARNUMBER" $FILENAME +[ -z "$YEARNUMBER" ] && echo "Input the year number:" && read -r YEARNUMBER +[ -n "$YEARNUMBER" ] && mid3v2 -y "$YEARNUMBER" "$FILENAME" # set tags for file -mid3v2 -a "$ARTISTNAME" -A "$ALBUMNAME" -t "$SONGNAME" -T "$TRACKNUMBER" $FILENAME +mid3v2 -a "$ARTISTNAME" -A "$ALBUMNAME" -t "$SONGNAME" -T "$TRACKNUMBER" "$FILENAME" -- cgit v1.2.3