I have a .sh script that automounts any usb device that is plugged in. I need it to also find if there are videos in a certain location on the device that is plugged in then write them to a videos.txt file. Here's what I have and its not working. Also I need it to put the mountpoint in the videos.txt file. ${MOUNTPOINT}$count is the path to the mounted device.
VIDEOS=ls ${MOUNTPOINT}$count/dcim/100Video | grep mp4
if [ "$VIDEOS" -ne "" ] ; then
"${MOUNTPOINT}$count" > ${MOUNTPOINT}$count/videos.txt;
"$VIDEOS" >> ${MOUNTPOINT}$count/videos.txt;
fi
What am I doing wrong?
VIDEOS=$(ls ${MOUNTPOINT}$count/dcim/100Video | grep mp4)
if [ -n "$VIDEOS" ] ; then
echo "${MOUNTPOINT}$count" > ${MOUNTPOINT}$count/videos.txt;
echo "$VIDEOS" >> ${MOUNTPOINT}$count/videos.txt;
fi
use $()
to execute process and return a value. use -n
test to check for non-zero strings. -ne
is used to check for numbers. $VIDEOS
by itself is a string, not a command. in order to put a value into a file, you should echo
it.