LinuxQuestions.org
Visit Jeremy's Blog.
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, 01: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, 02:50 PM   #2
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,619
Blog Entries: 1

Rep: Reputation: Disabled
Code:
echo "$latestTag" > /latestTag.txt
echo "$latestTag"
?
 
Old 01-15-2013, 04: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, 04:09 PM   #4
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 3,212

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 01:55 AM
Linking does not work as expected Setya Ubuntu 4 12-03-2008 01:05 PM
Script cd not work as expected cdcshu Linux - Software 1 11-10-2007 05:38 AM
If your hardware does not work as expected! Keruskerfuerst Suse/Novell 1 11-06-2005 06:43 AM
Echo /devPrinting doesn't work, echo /usb/lp0 works, Testpage works, Printing doesn't Hegemon Linux - General 3 08-15-2002 02:13 PM


All times are GMT -5. The time now is 06:04 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration