help-bash
[Top][All Lists]
Advanced

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

Re: Kludge for handling REPL arithmetic expressions


From: Eric Pruitt
Subject: Re: Kludge for handling REPL arithmetic expressions
Date: Wed, 4 Aug 2021 16:09:05 -0700
User-agent: Mutt/1.10.1 (2018-07-13)

On Wed, Aug 04, 2021 at 08:36:41AM -0700, Eric Pruitt wrote:
>         result="$(
>             expression="$(HISTTIMEFORMAT= \history 1)"
>             pc "x = $LAST_RESULT" "$(eval "echo \" ${expression#*=}\"")"
>         )"

I forgot to explain the eval bit here. I wanted to be able to use the
output of other commands in the expression e.g.:

    $ = $(find -iname '*.sh' | wc -l) / 2
    534.5 (1069/2)

On Wed, Aug 04, 2021 at 11:12:01AM +0100, Chris Elvidge wrote:
> 1) How do you 'export -f ='? Or is it impossible?

I never use "export -f", but with the way the command is implemented,
you can technically use "export -f" on the "calculate" function, but
without the two handler functions and the insertion of the "#" done by
the alias, you lose some functionality.

> 2) How do you type in '= log(2048,2)' without getting a syntax error?

The alias inserts a comment after the function name so the expression is
never parsed by the shell which ensures "*" and "**" don't get processed
as globs, (...) doesn't get processed as a subshell, etc.

Eric



reply via email to

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