I have made a simple backup program for my bin folder. It works.
Code and resultant STDOUT below.
Using rsync to copy from local ~/bin folder to a /media/username/code/bin folder. The code works fine when only one result from mount | grep media
but I can not quite fathom how to advance it to letting me select from multiple results from the mount/grep
.
I suspect the for LINE
below is lucky to work at all as I believe for
is delimited by spaces, in shell scripting, but as there are no spaces in the results it then delimited on the \n
? I tried find /media
and of course got a lot of results. Not the way to go I think. O_O
check_media () {
FOUNDMEDIA=$(mount | awk -F' ' '/media/{print $3}')
echo -e "foundmedia \n$FOUNDMEDIA"
echo For Loop
for LINE in $FOUNDMEDIA
do
echo $LINE
done
CHOSENMEDIA="${FOUNDMEDIA}/code/bin/"
echo -e "\nchosenmedia \n$CHOSENMEDIA\n"
exit
}
foundmedia
/media/dee/D-5TB-ONE
/media/dee/DZ61
For Loop
/media/dee/D-5TB-ONE
/media/dee/DZ61
chosenmedia
/media/dee/D-5TB-ONE
/media/dee/DZ61/code/bin/
You can see how I add the save path /code/bin
to the found media but with multiple results I get a chosenmedia
which cannot work. I would like to be able to choose the media to which I want to rsync my backup to, or restore from.
fzf
anddmenu
, they allow you to easily choose from a generated list, e.g.:CHOSENMEDIA=$(mount | awk ... | fzf)