to give a brief background on what I'm trying to do, simply put, I have configured dosbox to use my external midi keyboard (a usb to midi controller attached to a Casio keyboard)
on occasion the midi port number assigned to the midi cable changes (I move the computer often so the cable gets unplugged often), which requires me to manually change the number in ~/.dosbox/dosbox-0.xx.conf file, not a big deal really but it would be easier if i could do the change with a shell script
i have started on said said script and using grep, cut and if then statements have managed to compare the 2 values, now i just need a sed statement to actually perform the replacement and write the information back to the file
here is my script so far:
Code:
#!/bin/bash
# get the port number of the usb midi device
export alsa=`pmidi -l | grep USB | cut -d' ' -f2`
# check if a port number is present
if [ -z $alsa ]
then
#if nothing found, report this to the user and stop
echo 'no usb midi device found'
else
#aquire version of dosbox (used for the .conf file name)
export version=`dosbox --version | grep version | cut -d' ' -f 3 | cut -d, -f 1`
#report dosbox version found
echo 'dosbox version: '$version;
#report the current port number for the USB device
echo 'found using pmidi -l:' $alsa
#search the file for the port number dosbox is currently trying to use
export file=`cat ~/.dosbox/dosbox-"$version".conf | grep midiconfig= | cut -d= -f2`
#report the port number found in the dosbox.conf
echo 'found in dosbox conf file:' $file
#compare th e values;
if [ "$file" = "$alsa" ]
then
#if the dosbox.conf is current, report this to the user and stop
echo 'match found nothing to do'
else
#replace the contents of the file and report the change has been made
echo 'need sed statement to replace id found in dosbox.conf with output of pmidi -l'
echo 'file updated'
fi
fi