Re: Return from function depending on number of parameters

2020-07-10 Thread Greg Wooledge
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 [..

Re: Return from function depending on number of parameters

2020-07-10 Thread Chet Ramey
On 7/10/20 5:14 AM, Chris Elvidge wrote: > Are the two uses (array subscript and arithmetic context) of [...] > connected/related? Or am I (stupidly) seeing a connection where none really > exists? No doubt they resemble each other, since the bounding characters are the same and the contents are

Re: Return from function depending on number of parameters

2020-07-10 Thread Chris Elvidge
On 05/07/2020 06:24 pm, Chet Ramey wrote: On 7/4/20 12:23 PM, Lawrence Velázquez wrote: Quoting Chet liberally from https://lists.gnu.org/archive/html/bug-bash/2012-04/msg00034.html: It dates from Posix circa 1990 (1003.2d9, of which I've lost my paper copy). I implemented it after the Ber

Re: Return from function depending on number of parameters

2020-07-09 Thread Chris Elvidge
On 06/07/2020 12:50 pm, Greg Wooledge wrote: On Fri, Jul 03, 2020 at 07:00:54PM +0100, Chris Elvidge wrote: I've used 'return $((!$#))' and 'return $[!$#]' to return an error if no parameters given to function. The problem with this is that it *always* returns from the function, even when para

Re: Return from function depending on number of parameters

2020-07-06 Thread Greg Wooledge
On Fri, Jul 03, 2020 at 07:00:54PM +0100, Chris Elvidge wrote: > I've used 'return $((!$#))' and 'return $[!$#]' to return an error if no > parameters given to function. The problem with this is that it *always* returns from the function, even when paramters are given. If you actually want to do

Re: Return from function depending on number of parameters

2020-07-05 Thread Chet Ramey
On 7/4/20 12:23 PM, Lawrence Velázquez wrote: > Quoting Chet liberally from > https://lists.gnu.org/archive/html/bug-bash/2012-04/msg00034.html: >> >> It dates from Posix circa 1990 (1003.2d9, of which I've lost my paper >> copy). I implemented it after the Berkeley guys, mostly Marc >> Teitelba

Re: Return from function depending on number of parameters

2020-07-04 Thread Eli Schwartz
On 7/4/20 7:54 AM, Chris Elvidge wrote: > On 03/07/2020 11:16 pm, Eli Schwartz wrote: >> On 7/3/20 2:00 PM, Chris Elvidge wrote: >>> I've used 'return $((!$#))' and 'return $[!$#]' to return an error if no >>> parameters given to function. >>> >>> Tested in a bash script 'exit $((!$#)) / $[!$#]' -

Re: Return from function depending on number of parameters

2020-07-04 Thread Lawrence Velázquez
> On Jul 4, 2020, at 8:12 AM, pepa65 wrote: > > On 04/07/2020 04.39, Lawrence Velázquez wrote: >> It might tell you something that $[...] is not even mentioned in >> the man page for bash 3.2.57, which is decidedly not the current >> version. > > About that, is it for sure that $[] is going to b

Re: Return from function depending on number of parameters

2020-07-04 Thread Chris Elvidge
On 03/07/2020 11:16 pm, Eli Schwartz wrote: On 7/3/20 2:00 PM, Chris Elvidge wrote: I've used 'return $((!$#))' and 'return $[!$#]' to return an error if no parameters given to function. Tested in a bash script 'exit $((!$#)) / $[!$#]' - both work. 'echo $((!$#)) / $[!$#]' - both echo 1 when

Re: Return from function depending on number of parameters

2020-07-04 Thread Chris Elvidge
On 03/07/2020 10:39 pm, Lawrence Velázquez wrote: On Jul 3, 2020, at 2:00 PM, Chris Elvidge wrote: However 'N=0; echo $((!$N))' gives an error at the bash prompt. 'echo $[!$N]' echo's 1 as expected. My question - is $[...] actually obsolete? It might tell you something that $[...] is not eve

Re: Return from function depending on number of parameters

2020-07-04 Thread Oğuz
4 Temmuz 2020 Cumartesi tarihinde pepa65 yazdı: > On 04/07/2020 04.39, Lawrence Velázquez wrote: > > It might tell you something that $[...] is not even mentioned in > > the man page for bash 3.2.57, which is decidedly not the current > > version. > > About that, is it for sure that $[] is going

Re: Return from function depending on number of parameters

2020-07-04 Thread pepa65
On 04/07/2020 04.39, Lawrence Velázquez wrote: > It might tell you something that $[...] is not even mentioned in > the man page for bash 3.2.57, which is decidedly not the current > version. About that, is it for sure that $[] is going to be obsoleted/removed in the future? I happened to use it r

Re: Return from function depending on number of parameters

2020-07-04 Thread Chris Elvidge
On 03/07/2020 11:16 pm, Eli Schwartz wrote: On 7/3/20 2:00 PM, Chris Elvidge wrote: I've used 'return $((!$#))' and 'return $[!$#]' to return an error if no parameters given to function. Tested in a bash script 'exit $((!$#)) / $[!$#]' - both work. 'echo $((!$#)) / $[!$#]' - both echo 1 when

Re: Return from function depending on number of parameters

2020-07-04 Thread Chris Elvidge
On 03/07/2020 10:39 pm, Lawrence Velázquez wrote: On Jul 3, 2020, at 2:00 PM, Chris Elvidge wrote: However 'N=0; echo $((!$N))' gives an error at the bash prompt. 'echo $[!$N]' echo's 1 as expected. My question - is $[...] actually obsolete? It might tell you something that $[...] is not

Re: Return from function depending on number of parameters

2020-07-03 Thread Eli Schwartz
On 7/3/20 2:00 PM, Chris Elvidge wrote: > I've used 'return $((!$#))' and 'return $[!$#]' to return an error if no > parameters given to function. > > Tested in a bash script 'exit $((!$#)) / $[!$#]' - both work. > > 'echo  $((!$#)) / $[!$#]' - both echo 1 when no params, 0 when any > number of p

Re: Return from function depending on number of parameters

2020-07-03 Thread Lawrence Velázquez
> On Jul 3, 2020, at 2:00 PM, Chris Elvidge wrote: > > However 'N=0; echo $((!$N))' gives an error at the bash prompt. > 'echo $[!$N]' echo's 1 as expected. > > My question - is $[...] actually obsolete? It might tell you something that $[...] is not even mentioned in the man page for bash 3.2.

Return from function depending on number of parameters

2020-07-03 Thread Chris Elvidge
I've used 'return $((!$#))' and 'return $[!$#]' to return an error if no parameters given to function. Tested in a bash script 'exit $((!$#)) / $[!$#]' - both work. 'echo $((!$#)) / $[!$#]' - both echo 1 when no params, 0 when any number of params. I'm told ( https://wiki.bash-hackers.org/s