LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-22-2013, 07:58 PM   #1
Holering
Member
 
Registered: Feb 2010
Distribution: Slackware - Gentoo - Debian
Posts: 197

Rep: Reputation: 22
How do you export svn revision number to a variable within a script?


Can't grep or awk revision info when running an svn checkout script. Tried this:
Code:
svn checkout name.of.place/trunk
NAME=(svn checkout name.of.place/trunk | grep '^r[0-9]\+')
cp -r trunk nameofplace-$NAME ;\
exit 1
Only get "nameofplace-" so $NAME variable doesn't seem to work...

Help would be great!

Regards
 
Old 06-23-2013, 03:25 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by Holering View Post
Only get "nameofplace-" so $NAME variable doesn't seem to work...
Next time try debugging your shell script by setting "set -vx" at the appropriate place (add to command line, begin of script, this specific code location). The reason "nameofplace-$NAME" doesn't work is because you don't execute the command with back ticks or preferably with "$()". You should also always watch for proper quoting: "nameofplace-$NAME" or "nameofplace-${NAME}". Third you're using the "checkout" command twice for no other reason than retrieving the revision number. That's highly inefficient. Use another command line "info" instead.


Code:
VERSION=$(svn info name.of.place/trunk 2>&1|awk '/^Revision:/ {print $2}')
[ ${#VERSION} -ne 0 -a "X${VERSION//[0-9]/}" != "X" ] && echo cp -r trunk "nameofplace-${VERSION}"
 
1 members found this post helpful.
Old 06-26-2013, 10:35 PM   #3
Holering
Member
 
Registered: Feb 2010
Distribution: Slackware - Gentoo - Debian
Posts: 197

Original Poster
Rep: Reputation: 22
Thanks!

Ended up using:
Code:
VERSION=$(svn info http://place.net/trunk/ 2>&1|awk '/^Revision:/ {print $2}')
cp -r trunk "${PRGNAM}-r${VERSION}"
My only gripe is not being able to do this with a single variable.

If I use:
Code:
VERSION=$(svn checkout http://place.net/trunk | grep -o '[0-9]*')
cp -r trunk "${PRGNAM}-r${VERSION}"
it hangs and terminal has no output; when I ctrl-break and use svn manually it says it's locked and I have to use svn cleanup... Even if I do echo $VERSION prior to cp.

Would be nice to do this in one instance of svn rather than executing svn twice (svn checkout ; svn --info).

Last edited by Holering; 06-26-2013 at 10:39 PM.
 
Old 06-27-2013, 01:42 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
What you should understand firstly is that the 'checkout' command is the wrong tool for the job. Compared to 'info' it's an inefficient transaction because it provides more information than needed (it actually places code in the system while it's at all not necessary) and if you have a large code base it might take more time than strictly necessary. Secondly, and I don't know if this is a botched example or not, but your 'cp' command shows no destination. I don't know how a 'cp' should complete that way?.. Finally I pointed you to debugging your shell script by setting "set -vx". Using it (also in code you post?) helps you see and understand what goes on "under the hood". It comes in handy especially if you're not certain about the commands you use. Do try using it.
 
Old 06-28-2013, 12:47 AM   #5
Holering
Member
 
Registered: Feb 2010
Distribution: Slackware - Gentoo - Debian
Posts: 197

Original Poster
Rep: Reputation: 22
The cp command is run in the same working directory. Tried using set -vx but it shows nothing when running from script (didn't try outside the script). Thanks for your help.

Regards

Last edited by Holering; 06-28-2013 at 12:53 AM.
 
Old 06-28-2013, 11:43 AM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
It also helps to post an example of the text that you're working with, BTW. Both input and desired output. I was wondering if something cleaner couldn't be written, but I don't have any way to produce the type of svn output you're working on, so I'm unable to test any possible solutions for you.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
starting with git repos created from svn-all-fast-export, how to interact with svn? eantoranz Programming 0 03-16-2013 11:45 PM
Identify and explain the major number, minor number, and revision number in Linux... turbomen Linux - Newbie 1 11-16-2010 02:48 AM
In BASH shell, how do I export a variable from a script. MichaelG67 Linux - Software 2 06-24-2010 01:03 PM
svn checkout by revision number prayag_pjs Linux - Newbie 2 11-03-2009 07:44 AM
svn restore directory to a revision also removing files not part of revision Four Linux - Software 1 03-03-2009 04:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:15 PM.

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