ls output into a read command as a variable

I'm working on a short BASH script on my Ubuntu box that will run powerpoint scripts with MS Powerpoint Viewer 2007 via WINE.

I can run the presentation when I run it manually but what i'd like to do is have the script look for the newest file then run it.

#! /bin/sh

# Start the newest Powerpoint presentation

cd /powerpoint

ls | sort -n -t _ -k 2 | tail -1 > /tmp/newest.txt

cat /tmp/newest.txt | while read newppt

wine "C:\Program Files\Microsoft Office\Office12\PPTVIEW.EXE" /N /powerpoint/$newppt

Any ideas? I think im almost there but im having trouble turning the output of the ls command into a variable

man ls ("linux") has a 'sort by date' option, and you can pipe directly into read without the need for a temp file (although you don't actually need read in this case).

Try

ls -tr | tail -1 | read newppt

or

newppt=$(ls -tr | tail -1)

The latter is more bash friendly, as you need an explicit sub-shell, not always convenient, as '|(read newppt ; ... $newppt ....)' as otherwise the bash 'read' after '|' is in an implicit sub-shell like '|(read newppt), and the $newppt value is inaccessible to everything.

I usually do less i/o, as there is no point in typing more to make the thing you want the last! As fork is cheaper than exec, and no exec's cheaper than any exec's,if this fits your needs, it is fastest at 1 fork:

ls -t | (
 read newppt
 . . . $newppt . . . .
 )

or (2 forks and an exec):

newppt=$( ls -t | line )

or if line is not installed:

newppt=$( ls -t | head -1 )