LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Trying to echo into a file does not work as expected (http://www.linuxquestions.org/questions/linux-general-1/trying-to-echo-into-a-file-does-not-work-as-expected-4175445726/)

martin083 01-15-2013 01:26 PM

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
}

Habitual 01-15-2013 02:50 PM

Code:

echo "$latestTag" > /latestTag.txt
echo "$latestTag"

?

martin083 01-15-2013 04:00 PM

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.

suicidaleggroll 01-15-2013 04:09 PM

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.


All times are GMT -5. The time now is 09:23 AM.