From owner-freebsd-questions@FreeBSD.ORG Wed Jul 21 16:17:51 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3E9E1106564A for ; Wed, 21 Jul 2010 16:17:51 +0000 (UTC) (envelope-from swell.k@gmail.com) Received: from mail-fx0-f54.google.com (mail-fx0-f54.google.com [209.85.161.54]) by mx1.freebsd.org (Postfix) with ESMTP id BE0608FC15 for ; Wed, 21 Jul 2010 16:17:50 +0000 (UTC) Received: by fxm13 with SMTP id 13so4062096fxm.13 for ; Wed, 21 Jul 2010 09:17:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:references :date:in-reply-to:message-id:user-agent:mime-version:content-type; bh=xF8ApVR8fQbt3RgjG3V10isjGOn9FmFWOUpGpuu2jac=; b=l5I8JdH134x1w22/51Vvx/ZsRjxYW9X15hxlHVQxfpT/YGEliaRb4xTpzCX+uhGzS2 jkbuQKdSl4kCSTD/89fkk34zOe7f+KH3NY79+oc2/AI4RvcM/MRmD6lfg1Nhzgp3fM3U j5dt1dC9/W3c/0iVWPj4ArQqC9HjrrnoxzhKs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; b=xnM5bNLzKfCHZcqc+1kTJSuVUkv/bO0bE9Lf8pPcqGPmGiUevBoyrjzxiyFvAsUC2Y kJ7p1ohp19Op65bwgBLcOur3PYjn6XOp/W6J2qZ42CYZj+rjGAs6gY+UvjAGxGWFRfEb PvlNQzjW+5ddOJ4rjs8NI+45xsq8Day1pPZbs= Received: by 10.223.122.148 with SMTP id l20mr503287far.84.1279729068688; Wed, 21 Jul 2010 09:17:48 -0700 (PDT) Received: from localhost ([81.218.219.122]) by mx.google.com with ESMTPS id a9sm2947470faa.3.2010.07.21.09.17.43 (version=SSLv3 cipher=RC4-MD5); Wed, 21 Jul 2010 09:17:47 -0700 (PDT) From: Anonymous To: jimbob palmer References: Date: Wed, 21 Jul 2010 20:17:36 +0400 In-Reply-To: (jimbob palmer's message of "Wed, 21 Jul 2010 16:40:37 +0200") Message-ID: <866308stb3.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: freebsd-questions@freebsd.org Subject: Re: Bash logging: two questions X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Jul 2010 16:17:51 -0000 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...