LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-15-2013, 12:26 PM   #1
martin083
LQ Newbie
 
Registered: Mar 2010
Posts: 3

Rep: Reputation: 0
Trying to echo into a file does not work as expected


I have the following function that i am trying to wrong but it does not work as expected. I am trying to echo the latest CVS tag into a file but it does not happen.

getLatestTag () {
if [ ! -f /gamesrc/$1/Makefile ]
then
cd /
cvs co gamesrc/$1/Makefile > /dev/null
fi

# Obtain the line number of the latest tag
cd /gamesrc/$1/
lineNumber=`cvs status -v Makefile | grep -n "Existing Tags" | cut -f1 -d ':'`
lineNumber=`expr $lineNumber + 1`

# Format the latest tag correctly and echo it.
latestTag=`cvs status -v Makefile | sed -n ${lineNumber}p | sed 's/^[ \t]*//' | cut -f1`

echo $latestTag > /latestTag.txt
echo $latestTag
}
 
Old 01-15-2013, 01:50 PM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Code:
echo "$latestTag" > /latestTag.txt
echo "$latestTag"
?
 
Old 01-15-2013, 03:00 PM   #3
martin083
LQ Newbie
 
Registered: Mar 2010
Posts: 3

Original Poster
Rep: Reputation: 0
I am trying to write the result to the file and also pass the result back to whoever calls the function. The only way I have got it to work was by making another function that calls getLatestTag:

getLatestTag2 () {
getLatestTag $1 > /latestTag.txt
}

Not sure how this makes sense since I am doing the same thing again just in a different function. If I run my script in crontab then the file doesn't updated even if I use getLatestTag2.
 
Old 01-15-2013, 03:09 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Do you have write permission on /?
Any errors?
Cron has a very limited PATH, you'll need to hard code the path to many of your routines (cvs, etc) if you want to use it in cron.
 
1 members found this post helpful.
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting a INIT script to work as expected bombshell Programming 2 02-24-2011 12:55 AM
Linking does not work as expected Setya Ubuntu 4 12-03-2008 12:05 PM
Script cd not work as expected cdcshu Linux - Software 1 11-10-2007 04:38 AM
If your hardware does not work as expected! Keruskerfuerst SUSE / openSUSE 1 11-06-2005 05:43 AM
Echo /devPrinting doesn't work, echo /usb/lp0 works, Testpage works, Printing doesn't Hegemon Linux - General 3 08-15-2002 01:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:40 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