samedi 26 novembre 2016

use input from .txt file for if command shell linux

I need to write a script that plays a different sound every time it is ran. If you have an easier method then let me know. Right now the following script is what I have but I don't think the cat command is working like I want it to. Please assist.

#! /bin/sh
### BEGIN INIT INFO
# Provides:          rc.local
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Run /etc/rc.local if it exist
### END INIT INFO

if [ "cat /home/lucio/Desktop/welcomevar" = "10" ];
then
echo 1 > /home/lucio/Desktop/welcomevar; mplayer         /home/lucio/Desktop/sounds/welcome1.mp3
fi

if [ "cat /home/lucio/Desktop/welcomevar" = "1" ];
then
echo 2 > /home/lucio/Desktop/welcomevar; mplayer     /home/lucio/Desktop/sounds/welcome2.mp3
fi

if [ "cat /home/lucio/Desktop/welcomevar" = "2" ];
then
echo 3 > /home/lucio/Desktop/welcomevar; mplayer /home/lucio/Desktop/sounds/welcome3.mp3
fi

if [ "cat /home/lucio/Desktop/welcomevar" = "3" ];
then
echo 4 > /home/lucio/Desktop/welcomevar; mplayer     /home/lucio/Desktop/sounds/welcome4.mp3
fi

if [ "cat /home/lucio/Desktop/welcomevar" = "4" ];
then
echo 5 > /home/lucio/Desktop/welcomevar; mplayer         /home/lucio/Desktop/sounds/welcome5.mp3
fi

if [ "cat /home/lucio/Desktop/welcomevar" = "5" ];
then
echo 6 > /home/lucio/Desktop/welcomevar; mplayer     /home/lucio/Desktop/sounds/welcome6.mp3
fi

if [ "cat /home/lucio/Desktop/welcomevar" = "6" ];
then
echo 7 > /home/lucio/Desktop/welcomevar; mplayer     /home/lucio/Desktop/sounds/welcome7.mp3
fi

if [ "cat /home/lucio/Desktop/welcomevar" = "7" ];
then
echo 8 > /home/lucio/Desktop/welcomevar; mplayer     /home/lucio/Desktop/sounds/welcome8.mp3
fi

if [ "cat /home/lucio/Desktop/welcomevar" = "8" ];
then
echo 9 > /home/lucio/Desktop/welcomevar; mplayer /home/lucio/Desktop/sounds/welcome9.mp3
fi

if [ "cat /home/lucio/Desktop/welcomevar" = "9" ];
then
echo 10 > /home/lucio/Desktop/welcomevar; mplayer            /home/lucio/Desktop/sounds/welcome10.mp3
fi

exit 0




Aucun commentaire:

Enregistrer un commentaire