LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-18-2012, 10:38 AM   #1
lonesoac0
Member
 
Registered: Jan 2010
Distribution: Ubuntu
Posts: 101

Rep: Reputation: 4
Alternating Programs


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.
Attached Files
File Type: txt script.txt (645 Bytes, 12 views)
 
Old 01-18-2012, 11:39 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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.

Second:
Code:
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:
Code:
blah=$(cat $HOME/.number)
Third, you are mixing and matching numeric equality tests with string values. For instance:
Code:
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:
Code:
if [ "$blah" = "1" ]

...

if [ "$blah" = "2" ]
There may be more problems, but those are what I saw off-hand.

Last edited by Dark_Helmet; 01-18-2012 at 11:44 AM.
 
Old 01-18-2012, 12:18 PM   #3
lonesoac0
Member
 
Registered: Jan 2010
Distribution: Ubuntu
Posts: 101

Original Poster
Rep: Reputation: 4
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.
 
Old 01-18-2012, 09:18 PM   #4
lonesoac0
Member
 
Registered: Jan 2010
Distribution: Ubuntu
Posts: 101

Original Poster
Rep: Reputation: 4
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.
Attached Files
File Type: txt one_or_the_other.txt (689 Bytes, 12 views)
 
  


Reply

Tags
crontab, output, script, scripting



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Alternating between 2 web browsers as the same user = home dir gets messed? stf92 Slackware 5 06-12-2011 12:30 AM
HP deskjet 940c on linksys printserver prints alternating good page and bad page frogger Linux - Hardware 2 03-14-2011 02:54 PM
[SOLVED] KDE 4 - Weird skewed colors in qt4 programs after launching gtk programs. genericflounder Linux - Desktop 3 08-25-2010 04:41 PM
Alternating between Linux & Windows torrent clients dhave Linux - Software 2 12-14-2007 05:25 PM
Bash scripting alternating - / \ xvalentinex Programming 9 12-07-2005 12:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration