Output of last shell command

前端 未结 11 1520
渐次进展
渐次进展 2020-12-29 02:49

Not until midway through a 3 hour build script, I\'ll remember that I want to see something at the beginning of the output after it\'s done. At this point I\'ve exceeded th

相关标签:
11条回答
  • 2020-12-29 02:50

    No. The output of a program never passes through the shell's hands. Without redirection, it goes straight to the TTY. With redirection, it goes straight to whatever file or pipe it was directed to. The shell has no idea what the process sent to stdout/stderr.

    0 讨论(0)
  • 2020-12-29 02:50

    This could get very messy with certain commands that use cursor addressing. What's the output of your vim session? Or a slightly more sane example: You're downloading a file with wget, and it shows a percentage bar going from 0% to 100%. What's the output of that?

    I think you basically want a hardcopy of anything between your current line and the previous prompt. That's not something shell redirection would be a good example for, that's basically something a terminal would do. You could do it manually by copying and pasting in screen, and maybe you could automate it with its exec command. tmux might have something similar, and you can do weird things with the shell mode(s) of Emacs, but that's a rather heavyweight solution. rxvt-unicode has a perl extension…

    0 讨论(0)
  • 2020-12-29 02:52

    You can see the return code of the last command, at least in bash, with $?.

    As far stdout goes, I don't think you can.

    0 讨论(0)
  • 2020-12-29 02:54

    If running the command again won't change anything, you can use !! to access the top of the history stack to rerun the last command. Doing so in backticks will allow you to use the result.

    $> find . -iname fileInUnknownLocationInHierarchy.txt
    ./something/buried/deep/where/you/dont/want/to/retype/fileInUnknownLocationInHierarchy.txt
    $> vim `!!`
    
    0 讨论(0)
  • 2020-12-29 02:56

    How about using substitution. Like this:

    command1
    command2
    RESULT=`LASTCOMMAND`
    echo $RESULT

    0 讨论(0)
  • 2020-12-29 02:59

    You can always run the process inside an emacs shell window. It will keep everything.

    0 讨论(0)
提交回复
热议问题