Sample Header Ad - 728x90

Selecting from various media using awk shell script

1 vote
1 answer
68 views
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 }
bin is /home/dee/bin/
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.
Asked by Dee (33 rep)
Oct 17, 2022, 10:58 AM
Last activity: Oct 17, 2022, 12:44 PM