[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: unalias works weirdly inside an if-then block
From: |
Gabor Burjan |
Subject: |
Re: unalias works weirdly inside an if-then block |
Date: |
Fri, 12 May 2017 17:11:56 +0200 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
On Fri, May 12, 2017 at 09:10:07AM -0400, Greg Wooledge wrote:
> On Fri, May 12, 2017 at 02:33:06PM +0200, Gabor Burjan wrote:
> > unalias works weirdly inside an if-then block
>
> Because bash has to parse the entire compound command (the entire
> multi-line command up to "fi") before it can begin execution of it.
Greg,
Thanks for your answer. I'm coping with a legacy "enterprise"
installation framework which opens shell via ssh using expect, and the
target machine was a Red Hat based machine where cp is aliased. The
part where I could hook the process was after the function definition
which uses cp and therefore blocks the automatic running if cp becomes
interactive. The original hook was this
if [[ $- =~ i ]]; then
unalias cp
fi
but unfortunately this was later in the script than the function
definition. It's clear that the interactive mode is for interactive
usage, but I cannot change that part of the script. Now it's clear that
this will only work if it's on the top of the script, before the
function declaration.
Thanks again both for your help.
Regards,
Gabor