Skip to main content
Code Review

Return to Answer

updated the log file
Source Link
user173820
user173820

time is a Bash command that displays information on the shell standard error.

#!/bin/bash
PS4='+ ${FUNCNAME[0]}: '
set -o xtrace
exec 3>&2
runtime() ( time -p "$@" 2>&3 ) 2>runtime.log
# or runtime() { time -p "$@" 2>&3; } 2>runtime.log
runtime find "/usr"

runtime is a shell function executed in a subshell. The trick is to create a new file descriptor (fd3) that refers to the shell standard error (fd 2), then, override the subshell standard error (2>runtime.log) and redirect the error stream of the command to the shell standard error using the new file descriptor (2>&3).

prompt% cat runtime.log
+ ./test: line 9: (runtime): find /usr
real 64.82
user 1.62
sys 3.67

time is a Bash command that displays information on the shell standard error.

#!/bin/bash
PS4='+ ${FUNCNAME[0]}: '
set -o xtrace
exec 3>&2
runtime() ( time -p "$@" 2>&3 ) 2>runtime.log
# or runtime() { time -p "$@" 2>&3; } 2>runtime.log
runtime find "/usr"

runtime is a shell function executed in a subshell. The trick is to create a new file descriptor (fd3) that refers to the shell standard error (fd 2), then, override the subshell standard error (2>runtime.log) and redirect the error stream of the command to the shell standard error using the new file descriptor (2>&3).

prompt% cat runtime.log
+ ./test: line 9: (runtime): find /usr
real 64.82
user 1.62
sys 3.67

time is a Bash command that displays information on the shell standard error.

#!/bin/bash
PS4='+ ${FUNCNAME[0]}: '
set -o xtrace
exec 3>&2
runtime() ( time -p "$@" 2>&3 ) 2>runtime.log
# or runtime() { time -p "$@" 2>&3; } 2>runtime.log
runtime find "/usr"

runtime is a shell function executed in a subshell. The trick is to create a new file descriptor (fd3) that refers to the shell standard error (fd 2), then, override the subshell standard error (2>runtime.log) and redirect the error stream of the command to the shell standard error using the new file descriptor (2>&3).

prompt% cat runtime.log
+ runtime: find /usr
real 64.82
user 1.62
sys 3.67
revised the assignment of PS4
Source Link
user173820
user173820

time is a Bash command that displays information on the shell standard error.

#!/bin/bash
PS4='+ ${BASH_SOURCE[1]}: line ${BASH_LINENO[0]}: (${FUNCNAME[0]}): '
set -o xtrace
exec 3>&2
runtime() ( time -p "$@" 2>&3 ) 2>runtime.log
# or runtime() { time -p "$@" 2>&3; } 2>runtime.log
runtime find "/usr"

runtime is a shell function executed in a subshell. The trick is to create a new file descriptor (fd3) that refers to the shell standard error (fd 2), then, override the subshell standard error (2>runtime.log) and redirect the error stream of the command to the shell standard error using the new file descriptor (2>&3).

prompt% cat runtime.log
+ ./test: line 9: (runtime): find /usr
real 64.82
user 1.62
sys 3.67

time is a Bash command that displays information on the shell standard error.

#!/bin/bash
PS4='+ ${BASH_SOURCE[1]}: line ${BASH_LINENO[0]}: (${FUNCNAME[0]}): '
set -o xtrace
exec 3>&2
runtime() ( time -p "$@" 2>&3 ) 2>runtime.log
# or runtime() { time -p "$@" 2>&3; } 2>runtime.log
runtime find "/usr"

runtime is a shell function executed in a subshell. The trick is to create a new file descriptor (fd3) that refers to the shell standard error (fd 2), then, override the subshell standard error (2>runtime.log) and redirect the error stream of the command to the shell standard error using the new file descriptor (2>&3).

prompt% cat runtime.log
+ ./test: line 9: (runtime): find /usr
real 64.82
user 1.62
sys 3.67

time is a Bash command that displays information on the shell standard error.

#!/bin/bash
PS4='+ ${FUNCNAME[0]}: '
set -o xtrace
exec 3>&2
runtime() ( time -p "$@" 2>&3 ) 2>runtime.log
# or runtime() { time -p "$@" 2>&3; } 2>runtime.log
runtime find "/usr"

runtime is a shell function executed in a subshell. The trick is to create a new file descriptor (fd3) that refers to the shell standard error (fd 2), then, override the subshell standard error (2>runtime.log) and redirect the error stream of the command to the shell standard error using the new file descriptor (2>&3).

prompt% cat runtime.log
+ ./test: line 9: (runtime): find /usr
real 64.82
user 1.62
sys 3.67
BASH_SOURCE is an array variable
Source Link
user173820
user173820

time is a Bash command that displays information on the shell standard error.

#!/bin/bash
PS4='+ ${BASH_SOURCEBASH_SOURCE[1]}: line ${LINENOBASH_LINENO[0]}: (${FUNCNAME[0]}): }'
set -o xtrace
exec 3>&2
runtime() ( time -p "$@" 2>&3 ) 2>runtime.log
# or runtime() { time -p "$@" 2>&3; } 2>runtime.log
runtime find "/usr"

runtime is a shell function executed in a subshell. The trick is to create a new file descriptor (fd3) that refers to the shell standard error (fd 2), then, override the subshell standard error (2>runtime.log) and redirect the error stream of the command to the shell standard error using the new file descriptor (2>&3).

prompt% cat runtime.log
+ ./test: line 9: (runtime): find /usr
real 64.82
user 1.62
sys 3.67

time is a Bash command that displays information on the shell standard error.

#!/bin/bash
PS4='+ ${BASH_SOURCE}: line ${LINENO}: (${FUNCNAME[0]}): }'
set -o xtrace
exec 3>&2
runtime() ( time -p "$@" 2>&3 ) 2>runtime.log
# or runtime() { time -p "$@" 2>&3; } 2>runtime.log
runtime find "/usr"

runtime is a shell function executed in a subshell. The trick is to create a new file descriptor (fd3) that refers to the shell standard error (fd 2), then, override the subshell standard error (2>runtime.log) and redirect the error stream of the command to the shell standard error using the new file descriptor (2>&3).

prompt% cat runtime.log
+ ./test: line 9: (runtime): find /usr
real 64.82
user 1.62
sys 3.67

time is a Bash command that displays information on the shell standard error.

#!/bin/bash
PS4='+ ${BASH_SOURCE[1]}: line ${BASH_LINENO[0]}: (${FUNCNAME[0]}): '
set -o xtrace
exec 3>&2
runtime() ( time -p "$@" 2>&3 ) 2>runtime.log
# or runtime() { time -p "$@" 2>&3; } 2>runtime.log
runtime find "/usr"

runtime is a shell function executed in a subshell. The trick is to create a new file descriptor (fd3) that refers to the shell standard error (fd 2), then, override the subshell standard error (2>runtime.log) and redirect the error stream of the command to the shell standard error using the new file descriptor (2>&3).

prompt% cat runtime.log
+ ./test: line 9: (runtime): find /usr
real 64.82
user 1.62
sys 3.67
removed an unnecessary Bash expansion
Source Link
user173820
user173820
Loading
added 57 characters in body
Source Link
user173820
user173820
Loading
added 21 characters in body
Source Link
user173820
user173820
Loading
customized shell debug output
Source Link
user173820
user173820
Loading
added 115 characters in body
Source Link
user173820
user173820
Loading
Post Undeleted by Community Bot
Post Deleted by Community Bot
Source Link
user173820
user173820
Loading
lang-bash

AltStyle によって変換されたページ (->オリジナル) /