Ubuntu – Selecting multiple files with in bash

bashcommand linescripts

I want to use Scriptreplay with multiple log/timing files located in the same Directory.

The script I have right now looks like this:

select timings in /mnt/home/$USER/shell_logs/*; 
do
clear
scriptreplay $timings 
done;;
esac

Is there a way to select two files (the log and the timingfile of that log) at the same time?

Best Answer

The easiest way is if you can get there from the filename. For instance, if the selected filename is /mnt/home/$USER/shell_logs/20140326.log, you could get to another file in the same directory with a different extension, or another file in another directory pretty easily.

Let's first look at stripping the extension off:

timings="/mnt/home/$USER/shell_logs/20140326.timing" # just for testing
log="${timings%%.*}.log"
echo $log

And here's how to strip the leading path to change to a different directory:

log="/mnt/home/$USER/timings/${timings##*/}"
Related Question