LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 11-19-2009, 02:50 PM   #1
nrg
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Rep: Reputation: 0
Bash -- last output?


I couldn't find this documented, probably because I don't know the command.

I'm trying to get the last outputted line, AFTER the fact.

For example:

Code:
$ which bash
/usr/bin/bash

$
What command can I execute to get the string "/usr/bin/bash" from the previous result (without rerunning 'which bash')
 
Old 11-19-2009, 02:59 PM   #2
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 55
Quote:
Originally Posted by nrg View Post
I couldn't find this documented, probably because I don't know the command.

I'm trying to get the last outputted line, AFTER the fact.

For example:

Code:
$ which bash
/usr/bin/bash

$
What command can I execute to get the string "/usr/bin/bash" from the previous result (without rerunning 'which bash')
What do you want to do with it after you've got it?
 
Old 11-19-2009, 03:02 PM   #3
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
sasha@reactor:~$ hello=$(which bash)
sasha@reactor:~$ echo $hello
/usr/bin/bash
sasha@reactor:~$
 
Old 11-19-2009, 03:10 PM   #4
nrg
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Komakino View Post
What do you want to do with it after you've got it?
This is going to be used on a large 'ant build' output -- it's quite common that resources aren't updated in the build.xml, so I'll get an error such as:

Code:
BUILD FAILED
c:\app\trunk\build.xml:90: Error while expanding c:\app\trunk\resolved-lib\resource-1.1.jar
java.io.FileNotFoundException: c:\app\trunk\resolved-lib\resource-1.1.jar (The system cannot find the file specified)
My plan is to take the last output (java.io.FileNotFoundException: c:\app\trunk\resolved-lib\resource-1.1.jar (The system cannot find the file specified)) and extract the resource name, then 'find' the updated file (in this case, would be something like 'resource-1.2.jar') in resolved-lib, and transfer the new version number to the build.xml.

The build.xml line:
Code:
<unzip src="${ivy.resolved.lib.dir}/resource-1.1.jar" dest="${classes.dir}" />
 
Old 11-19-2009, 03:13 PM   #5
nrg
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Original Poster
Rep: Reputation: 0
It might actually be better to grep the build.xml file beforehand, and check for inconsistencies in the resolved-lib, so it wouldn't fail in the first place... I think I'll do that instead
 
Old 11-19-2009, 03:17 PM   #6
david1941
Member
 
Registered: May 2005
Location: St. Louis, MO
Distribution: CentOS7
Posts: 267

Rep: Reputation: 58
How about sending STDOUT to fileout and using $(tail -1 fileout) for the requested line?
 
Old 11-19-2009, 06:40 PM   #7
nrg
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Alright, I've written the script to parse through the build.xml and update it based on the files in the resolved-lib, the only problem I have now seems to be permission-based.

Code:
perl -p -i -e 's/resource-1.0.jar/resource-1.1.jar/g' ./build.xml
and

Code:
sed -i 's/resource-1.0.jar/resource-1.1.jar/g' ./build.xml
don't work when run in the .sh file, but works perfectly fine when I run it manually.

Any ideas?

Here's the full file, please go easy on me if I did something horribly wrong, haven't been doing this for very long

Code:
#!/bin/bash

buildfile="build.xml"

grep "unzip src=\"\${ivy" $buildfile | while read line; do
	fullname=$(echo $line|perl -pe 's/.+\/(.*?)".+/\1/')
	if [ -e ./resolved-lib/$fullname ]; then
		echo "found $fullname"
	else
		echo "$fullname not found"
		rootname=$(echo $fullname|perl -pe 's/(.+)-[0-9].+/\1-/')
		if [ -e ./resolved-lib/$rootname* ]; then
			newname=$(echo ./resolved-lib/$rootname*|perl -pe 's/.+\/(.+)/\1/')
			echo "GOT IT! $newname"
			perl -p -i -e 's/$fullname/$newname/g' ./$buildfile
			echo "perl -p -i -e 's/$fullname/$newname/g' ./$buildfile"
		else
			echo "$rootname not found"
			read #pause
		fi
	fi
done
 
Old 11-19-2009, 06:59 PM   #8
nrg
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Original Poster
Rep: Reputation: 0
even after I chmod build.xml to 777 (within the .sh, and it works) it doesn't update the file. Notepad++ is detecting a modification, but it's not actually changing the text
 
Old 11-19-2009, 07:35 PM   #9
nrg
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Ahh, the problem was the variables weren't working... changing the apostrophes to quotes worked, as such:

Code:
sed -i "s/$fullname/$newname/g" build.xml
 
  


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
[Bash] array `ls` output aoresearch Linux - Newbie 5 11-11-2009 08:21 AM
[SOLVED] bash: How i use locate output mythcat Programming 1 11-15-2008 11:35 AM
Format bash output ceashton Programming 3 08-17-2007 12:16 PM
BASH: let output like 00004 and not 4 bglnelissen Programming 9 09-28-2005 09:24 AM
BASH: Output everything between two strings systemparadox Programming 2 12-18-2004 10:26 AM

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

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