[Top][All Lists]

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

Re: Return from function depending on number of parameters

From: Greg Wooledge
Subject: Re: Return from function depending on number of parameters
Date: Fri, 10 Jul 2020 11:40:18 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

On Fri, Jul 10, 2020 at 10:14:38AM +0100, Chris Elvidge wrote:
> export PS1='\[${fcol[d]}${ecol[!!$?]}\][$?] \[${ucol[!!$(id
> -u)]}\]\h\[${fcol[b]}\]!\[${ucol[!!$(id -u)]}\]\u\[${fcol[w]}\]:(`tty|cut
> -d/ -f3-`):\D{%a %d %b %Y %I:%M %P %Z}:`pwd`\n\$\[${fcol[n]}\] '
> I somehow thought that [...] forced 'arithmetic context', so I tried it.

No, not in general.

> Are the two uses (array subscript and arithmetic context) of [...]
> connected/related? Or am I (stupidly) seeing a connection where none really
> exists?

An arithmetic context is created in (at least!) the following
situations (copied from

 * The $(( )) arithmetic substitution.
 * The let or (( )) command.
 * The index inside [ ] in an indexed array variable expansion.
 * The start and length parameters in ${parameter:start:length} substitution.
 * The [[ command with -gt or other numeric operators. 

The deprecated $[ ] substitution falls into the same category as the
currently supported $(( )) syntax.

The [ character has several different meanings depending on where
and how it's used.  It doesn't always indicate a math context.  It's
also used for character classes in globs and regular expressions.

reply via email to

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