Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 01-15-2013, 12:26 PM   #1
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 ]
cd /
cvs co gamesrc/$1/Makefile > /dev/null

# 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
LQ 5k Club
Registered: Jan 2011
Location: Nowhere near you, thank God.
Distribution: OSX Sierra
Posts: 8,570
Blog Entries: 14

Rep: Reputation: Disabled
echo "$latestTag" > /latestTag.txt
echo "$latestTag"
Old 01-15-2013, 03:00 PM   #3
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
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,527

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


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 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 > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:51 PM.

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