Bash logging: two questions

2010-07-21 Thread jimbob palmer
Hello,

I would like to run a bash script but to log output and exit codes.
Essentially I would like to run the script with bash -x, but for that
output to the log to go to a file, and the normal output as from
running a normal script to go to the terminal.

That's my first question :)

My second question is about history. Bash has a -h option to remember
the location of commands as they are looked up. Is it possible for
this to be recorded in the history? e.g. if I run ls, it would record
/bin/ls to the bash history file.

Many thanks.

JB
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: Bash logging: two questions

2010-07-21 Thread Anonymous
jimbob palmer  writes:

> Hello,
>
> I would like to run a bash script but to log output and exit codes.
> Essentially I would like to run the script with bash -x, but for that
> output to the log to go to a file, and the normal output as from
> running a normal script to go to the terminal.

Dunno about bash but in zsh it's easy

  #! /usr/bin/env zsh
  PS4='+%i:%N:%?> '
  exec 2>trace.log
  set -x

  # here goes the main script
  foo=5
  bar=$(date)
  echo foo=$foo, $bar
  false
  echo

It should work in sh(1) except you'll not see exit values in prompt.

Seems like bash doesn't have tcsh-like features: `%?' and printexitvalue.
I guess you'll have to write your own wrapper to put `$?' into stderr
after each command.

> My second question is about history. Bash has a -h option to remember
> the location of commands as they are looked up. Is it possible for
> this to be recorded in the history? e.g. if I run ls, it would record
> /bin/ls to the bash history file.

If bash has smth like zshaddhistory() it'd be easy...
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"