Results 1 to 6 of 6
My BASH script populates the id3tag from pre-existing id3 tags and/or the filename. The script has id3lib dependencies (id3tag, id3info, and id3convert). I would like to make the script more ...
- 04-04-2007 #1Just Joined!
- Join Date
- Oct 2005
- Posts
- 11
Editable input and using read
My BASH script populates the id3tag from pre-existing id3 tags and/or the filename. The script has id3lib dependencies (id3tag, id3info, and id3convert). I would like to make the script more interactive and allow the user to build the id3 tags if necessary. Currently, the script is fairly crude (no error checking and design for specific naming convention).
Id3tag builds the tag information similar to the following line (this line is just an example).
Basically, my script builds an array with all the option to pass to the ID3tag.Code:id3tag --artist=$ARTIST --song=$SONG --album=$ALBUM --year=$YEAR --track=$NUM --genre=$GENRE
I want to prompt the user with the id3tag parameters and allow them to edit them; and pass them to the script. The prompt would allow the user to populate the tags; edit the id3tag parameters; or skip tagging for this file. I don’t know how to present editable input to the user; pass the edited input to the script; and execute it. Here is my work-in-progressCode:id3tag ${TAGS[@]}
I am also having trouble with the “read” command. The line below does not prompt the user for input. The script does not pause to read from the console. Both code blocks are found within a while loop.Code:echo "id3tag ${TAGS[@]}" read -p "Do you want to run populate the ID3 tag (y,n,edit)?" ANSWER case $ANSWER in [Yy]*) id3tag ${TAGS[@]};; [Nn]*) echo 'Exiting' continue;; esac
Code:if [ "$ALBUM" = "" ]; then echo "ID3 tag does not contain ALBUM" read -p "Please enter the Album" ALBUM TAGS[i++]="--album=\"$ALBUM\"" else TAGS[i++]="--album=\"$ALBUM\"" fi
- 04-04-2007 #2
That read statement works fine, Are you saying it shows Please enter the album but then just keeps going?
- 04-05-2007 #3Just Joined!
- Join Date
- Oct 2005
- Posts
- 11
Yes, the script does not pause at the “read” statement and does not allow the user to enter a value. The script does echo the “Please enter the album;” which shows that the "if" condition was met. The script does not stop at theThat read statement works fine, Are you saying it shows Please enter the album but then just keeps going?
“read -p "Do you want to run populate the ID3 tag (y,n,edit)?" ANSWER”
A while loop contains both these read statements. Could this be an issue? My script does not return error otherwise.
- 04-05-2007 #4
- 04-06-2007 #5Just Joined!
- Join Date
- Oct 2005
- Posts
- 11
I have gained some insight on my problem. It may relate to where the read command output goes when piped through multiple commands. The “read” command resides in a piped loop, thus my redirection was going somewhere else (unknown to me). I am still trying to wrap my head around stdin, stdout, and stderror in relationship to pipe commands. So I have not been able to resolve my “read” issues; and now I have to understand how to redirect my “find” and “while” commands. The goal is to redirect the keyboard input to the stdout (I guess). Then stderr may need redirection.
I understand the fundamentals behind redirection.
stdin equals 0
stdout equals 1
stderr equals 2
2>&1 # send stderr to the same place as stdout
3<&0 # send stdin to a file descriptor 3; little confused here
The exec command adds to the confusion as well.
My Bash script has code similar to below. This code is crude and may contain numerous mistakes. Presently, I learning the syntax and build upon a previously working script. The pseudo code here just illustrates my situation (and does not to showcase scripting knowledge).
Code:find . -name \*.mp3 -type f -print | while read FILE do i=0 FILE=${FILE##*/} TAG=`id3info "$FILE"` TITLE2=$(echo "$TAG" | awk -F ":" '/TIT2/ { print $2}' | sed -e 's/^ *//' -e 's/ *$//') ALBUM1=$(echo "$TAG" | awk -F ":" '/TALB/ { print $2}' | sed -e 's/^ *//' -e 's/ *$//') # Other code here if [ -z "$ALBUM" ]; then # DOES NOT PAUSE FOR INPUT echo "ID3 tag does not contain ALBUM" history -s "$ALBUM" printf "Press up arrow to edit current value (%s)\n" "$ALBUM" read -ep "Enter album title: " VAR ALBUM="$VAR" TAGS[i++]="--album=\"$ALBUM\"" else TAGS[i++]="--album=\"$ALBUM\"" fi # More code here echo"id3tag ${TAGS[@]}" # DOES NOT PAUSE FOR INPUT read -p "Do you want to run populate the ID3 tag (y,n,edit)?" ANSWER case $ANSWER in [Yy]*) id3tag ${TAGS[@]} ;; [edit]*) history -s "id3tag ${TAGS[@]}" printf "Press up arrow to edit current value (%s)\n" read -ep "Edit the ID3tag parameter: " VAR ;; [Nn]*) echo 'Exiting' continue ;; esac done
- 04-06-2007 #6
That find | while isn't going to work as far as I can tell. You can get something functionally similar by doing
Code:for FILE in *.mp3; do stuff goes here done


Reply With Quote