-   Linux - Newbie (
-   -   Alternating Programs (

lonesoac0 01-18-2012 10:38 AM

Alternating Programs
1 Attachment(s)
Hello all,

I am trying to make a script that alternates application execution. The applications that I am trying to execute are Feh and Mplayer. Feh is an image viewer application and mplayer is a movie player application. Initially I tried to make the script read the values 1 or 2 from a text file and based off of that value the desired application will start. The bottom half of my script actually changes the value in my text file but the top half does not change the value. In addtion I am trying to get this script to be run by crontab. I keep getting the weird results of something like: ::::::::: /home/user_name/.number :::::::::: in my output file.

Dark_Helmet 01-18-2012 11:39 AM

First, when I open that text file, emacs tells me that it's using DOS line endings. You need to run dos2unix on the script to change the DOS line endings to Unix line endings. The DOS line endings can cause some pretty odd problems.


blah=$(more $HOME/.number)
I would not use the more command. The more command is an interactive pager. It waits for user input--even if the file being displayed is a single line. You probably should use:

blah=$(cat $HOME/.number)
Third, you are mixing and matching numeric equality tests with string values. For instance:

if [ "$blah" -eq "1" ]


if [ "$blah" -eq "2" ]

The -eq, -lt, -gt, and similar comparison operators are for comparing numeric values--not strings. To test that two strings match, you should use =, !=, etc. For example:

if [ "$blah" = "1" ]


if [ "$blah" = "2" ]

There may be more problems, but those are what I saw off-hand.

lonesoac0 01-18-2012 12:18 PM

I am not surprised my formatting was off. I opened the .txt file from windows, copied the info from it and pasted it into an e-mail and sent it to a different e-mail. I was in a rush. :) I thought that I could use cat instead of more. I tried it a few time but for some reason or another it did not pan out so I ended up going back to more. Guess that is what happens when I play with scripting when I am sleepy. I will make the modifications tonight.

lonesoac0 01-18-2012 09:18 PM

1 Attachment(s)
Dark Helmet,

You saved me again man! I did the changes that you said and I got it to work like a charm. I added a small tid-bit of code at the end to make the file if it does not exist. I have attached my modified script.

All times are GMT -5. The time now is 06:50 PM.