[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] counter for executed commands in non interactive mode?
From: |
Meike Stone |
Subject: |
Re: [Help-bash] counter for executed commands in non interactive mode? |
Date: |
Tue, 19 May 2015 10:31:36 +0200 |
Thanks all for help!
2015-05-18 19:49 GMT+02:00 Chet Ramey <address@hidden>:
> On 5/18/15 11:57 AM, Meike Stone wrote:
>>>> is there a easy way, to count inside a bash script the executed
>>>> (external) commands while this script itself is executed?
>>>> Normaly, the commands are counted in the interactive mode and
>>>> displayed in the command prompt if "\#" is configured.
>>>> Maybe, there is a possibility to access this counter?
>>>
>>> The shell attempts to count the number of commands executed, but it's
>>> not limited to external executed commands: it includes both compound
>>> and simple commands, including builtins and shell functions. The \#
>>> prompt expansion is the only place where that count is exposed.
>>
>> ... but it is not possible to access this internal counter?
>
> Correct. The only place that count is exposed is the \# prompt expansion.
Ok, so as mentioned, strace is my friend:
strace -f -e execve ./test.sh 2>&1 >/dev/null | grep execve
> We can talk about extensions to expose it in other ways (e.g., some new
> variable), but it's only an approximation and not guaranteed to be the
> right value for everyone.
For my tests this would be too much, but maybe it is a good idea to
enhance the bash
by such variable, because it can help to prevent prodigal using of
external commands ;-)
Meike