help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Usage of $BASH_COMMAND inside an auto retry function? Is


From: Chet Ramey
Subject: Re: [Help-bash] Usage of $BASH_COMMAND inside an auto retry function? Is there an expanded $BASH_COMMAND?
Date: Tue, 14 Mar 2017 21:14:38 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.7.1

On 3/9/17 8:25 PM, Patrick Schleizer wrote:
> Hi,
> 
> I am using $BASH_COMMAND in a build script inside an ERR trap to
> implement auto retry. (Some stuff temporarily fails due to network
> issues but works on second attempt.)
> 
> Two things do not work well with $BASH_COMMAND.
> 
> a) When the last command contained variables. I.e.
> 
> some_variable="--some-switch"
> apt-get $some_variable
> 
> Then BASH_COMMAND would just contain 'apt-get' but not '--some-switch'.
> Is there an expanded variable similar to BASH_COMMAND that would hold
> 'apt-get --some-switch'?

More precisely, it gets "apt-get $some_variable".  There is no variable
that holds the command after it's been expanded.  You can always run the
value through "eval" but you should be prepared to deal with any
command substitutions or process substitutions that would be expanded.

> 
> b) Will not be possible to repeat a failed pipe command. For example:
> echo something | apt-get
> 
> Then BASH_COMMAND will hold only 'apt-get'. Is there a variable that
> holds the full command 'echo something | apt-get' so it cold be retried?

`apt-get' is the last command executed, so that's what ends up in
BASH_COMMAND.

You might be able to look at the last history entry if you enable history
in your script.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]