Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

turn off ZSH glob expansion in function arguments in interactive shell

Tags:

zsh

glob

When I find myself in times of arithmetic trouble¹, I like to simply calculate on my shell

> echo $(( 3**4 - 2/7*5 ))

which of course works beautifully. However, I find that it's too much typing, so I defined

function §()
    echo $(( $@ ))

which allows me to

> § '3**4 - 2/7*5'

but not

> § 3**4 - 2/7*5

Because zsh tells me it could find no matches (or worse, expands filenames if there are some matches).

How can I tell the zsh shell that I want it to not interpret things entered as arguments to a function as globs?

I don't want to do something like

> enter_non_glob_mode
> 3**4 - 2/7*5
> back_to_normal_mode

because instead of that, I could as well start dc, python


¹Mother Euler speaks to me, wispering words of wisdom, power of e... SCNR.

like image 401
Marcus Müller Avatar asked Oct 29 '25 08:10

Marcus Müller


1 Answers

Use the noglob modifier.

% noglob § 3**4 - 2/7*5
81

To avoid having to type noglob each time, use an alias to insert the modifier. (You can't put noglob inside the function, as pathname expansion will have already taken place before the body is evaluated.)

% alias §='noglob §'
% § 3**4 - 2/7*5
81
like image 197
chepner Avatar answered Oct 31 '25 10:10

chepner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!