Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

So I often get messages such as You have new mail in /var/spool/mail/root and end up typing/copy-pasting out: tail /var/spool/mail/root, which is a bit cumbersome.

Is there a simple command that will do this (i.e. grab something that looks like a directory from the previously outputted line in bash) instead?

share|improve this question
3  
Have you tried... checking your mail? –  Michael Hampton Feb 11 '13 at 20:17
add comment

2 Answers 2

As this is always the same path I think it doesn't make sense to put effort into that. You could disable the bash feature (MAILCHECK=0) and put your own check code into PS1. But why bother, if

alias new_mail="tail /var/spool/mail/root"

does all you need?

share|improve this answer
1  
This answers only the specific example, however, the user is asking for a more general capability that this answer does not provide. –  mdpc Feb 11 '13 at 20:15
    
Yeah this is a nice solution to my specific problem, but if there was a way to grab previous text in bash that would be awesome –  LittleBobbyTables Feb 11 '13 at 20:18
    
If I was aware of a general way I would have mentioned it. Should I not have pointed out the specific solution? It should be possible to create something within PS1 (probably beyond "simple" for average perception) that checks this for virtual terminals (screendump) or screen sessions with enabled logging but that's far from general. –  Hauke Laging Feb 11 '13 at 20:44
add comment

Don't be lazy.

Copy/paste is the standard solution for this. Of course, the example you give could be remediated with the mail command, but I understand that there may be other other examples that could benefit.

For instance, I use the Eterm terminal on my Mac and Linux systems. It parses directory paths and URL's incredibly well (PuTTY doesn't). xterm and rxvt do the same. The double-click action is based on the delimiter defined as cutChars; Typically, those are spaces and any of the following:

\\ `\"\'()*;<>[]{|}

Double-click for the URL/path.
Triple-click to grab the URL/path to the end of the line.

That may make your copy/pasting action more convenient. It's a small detail...

enter image description here

share|improve this answer
    
I'm giving you an upvote since this is a nice answer, but its not quite the previous bash text-grabbing solution that I am currently searching around for. But Thanks :) –  LittleBobbyTables Feb 11 '13 at 21:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.