Re: Behaviour of test -v with assoc array and quote character in key

2021-02-23 Thread Andreas Schwab
On Feb 23 2021, Greg Wooledge wrote:

> No amount of quoting will make (( 'assoc[$var]'++ )) work.

(( assoc[var]++ ))

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: syntax error while parsing a case command within `$(...)'

2021-02-17 Thread Andreas Schwab
On Feb 17 2021, Koichi Murase wrote:

> Yes, that's what I wanted to claim by the above example, that is, XCU
> 2.4 isn't the (most) essential point for the reason that `fi esac' or
> `fi fi` is a valid construct. The above example is just a
> counter-example against explaining `fi esac` by solely XCU 2.4.

XCU 2.4 only explains when words are to be recognized as reserved words
(the lexer part of parsing).  Only because of these rules the `fi esac'
example contains two consecutive reserved words.  The grammar depends on
having these rules in place, and then applies more rules on the
placement of tokens.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: syntax error while parsing a case command within `$(...)'

2021-02-16 Thread Andreas Schwab
On Feb 16 2021, Koichi Murase wrote:

> Because the ending keywords---}, fi, done, and esac---are allowed to
> be chained, which I think is undocumented though.

See 2.4 Reserved Words.

This recognition shall only occur when none of the characters is
quoted and when the word is used as:

* The first word of a command
* The first word following one of the reserved words other than
  case, for, or in
* The third word in a case command (only in is valid in this case)
* The third word in a for command (only in and do are valid in this
  case)

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: syntax error while parsing a case command within `$(...)'

2021-02-14 Thread Andreas Schwab
On Feb 14 2021, Eli Schwartz wrote:

> On 2/14/21 3:35 PM, Andreas Schwab wrote:
>> On Feb 14 2021, Eli Schwartz wrote:
>> 
>>> Just a running trend that esac does not get recognized without a
>>> separator.
>> 
>> $ bash -c 'case x in x) esac'
>
> The thread title does mention $(...) as the relevant context up for
> discussion. Apologies if my terseness made you think I've moved off of
> the thread subject; I did not do so.

It's still a counterexample.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: syntax error while parsing a case command within `$(...)'

2021-02-14 Thread Andreas Schwab
On Feb 14 2021, Eli Schwartz wrote:

> Just a running trend that esac does not get recognized without a
> separator.

$ bash -c 'case x in x) esac'

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: syntax error while parsing a case command within `$(...)'

2021-02-13 Thread Andreas Schwab
On Feb 14 2021, Robert Elz wrote:

> Date:Sat, 13 Feb 2021 23:21:36 +0300
> From:=?UTF-8?B?T8SfdXo=?= 
> Message-ID:  
> 
>
>   |   $ bash -c ': $(case x in x) esac)'
>
> This is a well known bash deficiency.  When parsing command substitutions
> it (approximately) simply counts (unquoted) parentheses to find the end.
> Anything with a valid closing ')' but with no opening '(' confuses it.

Bash already handles that properly, when the compound-list is non-empty.

$ bash -c ': $(case x in x) :; esac)'

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: ${a:=b} expands to `b', not `a''s value

2021-01-20 Thread Andreas Schwab
On Jan 20 2021, Léa Gris wrote:

> Le 20/01/2021 à 13:51, Andreas Schwab écrivait :
>> But that's not the value of the parameter.
>
> It is not, since at this point, the parameter has no value,

That is not true.  Otherwise the expansion would be empty.

> the expansion expands the argument's value after ;= which is uppercase
> X here.

No, the parameter has the value x.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: ${a:=b} expands to `b', not `a''s value

2021-01-20 Thread Andreas Schwab
On Jan 20 2021, Léa Gris wrote:

>> The value of parameter is then substituted.
>
> The expansion part:
> The value X is expanded but is not affected by the lowercase
> transformation flag from a, so it remains as X.

But that's not the value of the parameter.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Feature: where terminal reports mouse click to bash, support positioning the cursor accordingly

2021-01-18 Thread Andreas Schwab
On Jan 18 2021, Chet Ramey wrote:

> What information does the terminal emulator pass to the application to
> indicate the desired position?

Emacs supports it as xterm-mouse-mode.  See
<https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking>.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: [EXT] Re: Bash 5.1: rl_readline_version = 0x801 (shouldn't it be 0x0801 ?)

2020-12-08 Thread Andreas Schwab
On Dez 08 2020, Greg Wooledge wrote:

> On Tue, Dec 08, 2020 at 09:47:05AM +0100, Andreas Schwab wrote:
>> On Dez 07 2020, Testing Purposes wrote:
>> 
>> > From an integer standpoint, I know that 08 (with one leading zero) is the
>> > same as 8.
>> 
>> Nope, it is a syntax error.
>
> In a bash math context or in C, 08 is indeed a syntax error, as it is
> an octal integer constant with an invalid digit ("8").
>
> In mathematics, 08 is just 8.

This is all about C, so mathematics don't come into play.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: bash doesn't display user-typed characters; can interfere with COPY/PASTE

2020-12-08 Thread Andreas Schwab
Just use history or fc -l to display the line as is.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Bash 5.1: rl_readline_version = 0x801 (shouldn't it be 0x0801 ?)

2020-12-08 Thread Andreas Schwab
On Dez 07 2020, Testing Purposes wrote:

> From an integer standpoint, I know that 08 (with one leading zero) is the
> same as 8.

Nope, it is a syntax error.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Possible race condition in bash

2020-11-21 Thread Andreas Schwab
On Nov 21 2020, Chet Ramey wrote:

> but since the shell always ignores SIGTERM,

Even a non-interactive shell?

> I'd also try it with one of the bash-5.1 testing releases, since I did
> some reworking of how the shell handles SIGTERM back in April.

5.1-rc3 has the same issue.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Possible race condition in bash

2020-11-21 Thread Andreas Schwab
On Nov 21 2020, Chet Ramey wrote:

> This is a potential race condition, but it's not with the shell.

The race with the trap command in the function is obvious, but that
should not result in the signal to be ignored.  There should always be a
trap active, either the main one or the one in the function, and neither
ignores the signal.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Problems with command substitution and command alias

2020-11-21 Thread Andreas Schwab
On Nov 22 2020, Hyunho Cho wrote:

> if i run following command ( including "prompt$" )
> then "command not found" error occurred
> but "$( mktemp -d -p /dev/shm )" command substitution executed completely

The expansion is of course performed before the command is executed.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: is it a bug

2020-11-17 Thread Andreas Schwab
$ alias x='a=()
foo
echo $a'
$ x
foo
$ declare -p a
declare -a a=([0]="foo")

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: bash: please provide an easy way to spawn a new process group from script

2020-11-01 Thread Andreas Schwab
On Nov 01 2020, clime wrote:

> Please, provide a syntactic construct to spawn a new process group (or
> at least there should be some usable command to do that).

Enable job control.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Bad substitution breaks conditional statement

2020-10-14 Thread Andreas Schwab
On Okt 14 2020, Martin Schulte wrote:

> Consider the following script:
>
>>>>
> #!/bin/bash
>
> echo "${x;:-}" ; echo "Not executed"
> echo "Executed"
>
> echo "${x:-}" ;; echo "Not executed"
> echo "Not executed"
> <<<
>
> It just a source of problems that the two syntactical errors (both caused by 
> an extra semicolon) lead to different behaviour.

The difference being that the first error occurs during execution, while
the latter occurs during parsing.  The latter is also caught by bash -n.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Bash-5.1-beta available

2020-10-08 Thread Andreas Schwab
On Okt 08 2020, Chet Ramey wrote:

> There's no good way to tell whether or not a terminal supports bracketed
> paste, but I suppose this is as good a start as any. Remember that gdb
> can always turn it off while running the test suite.

It needs to be controllable from the outside.  gdb itself doesn't
provide any command line interface to the readline configuration, and
the testsuite framework sets INPUTRC=/dev/null on purpose (to avoid any
disturbance).

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Bash-5.1-beta available

2020-10-07 Thread Andreas Schwab
On Okt 07 2020, Chet Ramey wrote:

> On 10/7/20 12:42 PM, Andreas Schwab wrote:
>> On Sep 10 2020, Chet Ramey wrote:
>> 
>>> h. Bracketed paste mode is enabled by default (for now).
>> 
>> Shouldn't that be disabled on a dumb terminal?  This wrecks havoc on the
>> gdb testsuite.  It sets TERM=dumb to tell readline not to do any fancy
>> output, but this no longer works.
>
> The gdb test suite tests pasting?

It uses expect.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Bash-5.1-beta available

2020-10-07 Thread Andreas Schwab
On Sep 10 2020, Chet Ramey wrote:

> h. Bracketed paste mode is enabled by default (for now).

Shouldn't that be disabled on a dumb terminal?  This wrecks havoc on the
gdb testsuite.  It sets TERM=dumb to tell readline not to do any fancy
output, but this no longer works.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: execve E2BIG (Argument list too long)

2020-09-30 Thread Andreas Schwab
On Sep 30 2020, Daniel Colascione wrote:

> It might be worth asking lkml to lift this restriction

You will have bad luck with that.  The limit has been introduced for
security reasons.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Bash-5.1-beta available

2020-09-22 Thread Andreas Schwab
On Sep 21 2020, Dale R. Worley wrote:

> Andreas Schwab  writes:
>> On Sep 10 2020, Chet Ramey wrote:
>>
>>> yy. Process substitution processes now get their input from /dev/null, since
>>> they are asynchronous, not interactive, and not jobs.
>>
>> That breaks scripts that want to filter stdin with a process
>> substitution, eg:
>>
>> while read ...; do ...; done < <(filter)
>
> I'm assuming you mean "<( ... )" process substitutions,

Which is exactly what I wrote.

> I assume that if you really want the old effect, you can still do

That point is that it silently breaks existing scripts.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Bash-5.1-beta available

2020-09-13 Thread Andreas Schwab
You have a regression here though:

cat <

Re: Bash-5.1-beta available

2020-09-13 Thread Andreas Schwab
On Sep 10 2020, Chet Ramey wrote:

> qqq. Fixed a bug that could cause backslashes quoting double quotes in here
>  document bodies to not be removed when expanding the body.

Are you sure about this?  My reading of POSIX says that a backslash
before a double quote should not be removed, as double quotes are not
special in here docs.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Bash-5.1-beta available

2020-09-11 Thread Andreas Schwab
On Sep 11 2020, Jesse Hathaway wrote:

> On Fri, Sep 11, 2020 at 5:40 AM Andreas Schwab  wrote:
>> The reason for using a process substitution is so that the loop can set
>> shell variables.
>
> Would using lastpipe be an option instead?

No, the scripts are out there and will break.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Bash-5.1-beta available

2020-09-11 Thread Andreas Schwab
On Sep 10 2020, Chet Ramey wrote:

> yy. Process substitution processes now get their input from /dev/null, since
> they are asynchronous, not interactive, and not jobs.

That breaks scripts that want to filter stdin with a process
substitution, eg:

while read ...; do ...; done < <(filter)

The reason for using a process substitution is so that the loop can set
shell variables.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: No word splitting for assignment-like expressions in compound assignment

2020-07-27 Thread Andreas Schwab
On Jul 27 2020, Lawrence Velázquez wrote:

> If word splitting were not performed in compound assignments, this...
>
> foo=(a b c)
>
> ...would not work.

This is not true.  Field splitting is only relevant for words generated
by other expansions, not for literal tokens.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: (IMPORTANT/URGENT) Regarding Missing Files in bash source code?

2020-07-17 Thread Andreas Schwab
On Jul 17 2020, Chet Ramey wrote:

> So Greg's advice is appropriate: find out why bison is looking for that
> file,

It is one of its installed files used during runtime.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: ‘command … &’ creates subshell

2020-07-01 Thread Andreas Schwab
On Jul 02 2020, Robert Elz wrote:

> POSIX says:
>
>   If command is specified, exec shall not return to the shell;

But it also says:

If command is not found, the exit status shall be 127. If command is
found, but it is not an executable utility, the exit status shall be
126.

And that's what bash does.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Bash-5.1-alpha available for download

2020-06-17 Thread Andreas Schwab
$ make install DESTDIR=/home/abuild/rpmbuild/BUILDROOT/bash-5.0-lp151.10.125.1.x
86_64

  ***
  * *
  * GNU bash, version 5.1.0(1)-alpha (x86_64-suse-linux-gnu)
  * *
  ***

mkdir -p -- 
/home/abuild/rpmbuild/BUILDROOT/bash-5.0-lp151.10.125.1.x86_64/usr/share/man/man1
( cd ./po/ ; make  
DESTDIR=/home/abuild/rpmbuild/BUILDROOT/bash-5.0-lp151.10.125.1.x86_64 
installdirs )
make[1]: Entering directory '/home/abuild/rpmbuild/BUILD/bash-5.1-alpha/po'
/bin/sh @MKINSTALLDIRS@ 
/home/abuild/rpmbuild/BUILDROOT/bash-5.0-lp151.10.125.1.x86_64/usr/share
/bin/sh: @MKINSTALLDIRS@: No such file or directory
make[1]: *** [Makefile:326: installdirs-data-yes] Error 127

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: How functions are defined

2020-04-28 Thread Andreas Schwab
On Apr 27 2020, Dale R. Worley wrote:

> So it seems the reserved rule is more accurately:
>
>Reserved words are words that have a special meaning to the
>shell.  The following words are recognized as reserved when
>unquoted and either (1) where the first word of a simple command
>could be (see SHELL GRAMMAR below), (2) the third word of a case,
>for, or select command, the (3) first word of the body of a function
>definition, or (4) after a semicolon or newline:
>
> IIUC there are two places where the documentation needs to be updated,
> bash/doc/bash.1 and bash/doc/bashref.texi.  But the above wording is a
> lot more complex than I'd like.  Does anyone have suggestions for a
> clearer way to say this that is still accurate?
>
> ... Looking at this again, I think (1) and (3) can be replaced by "the
> first word of a command (see SHELL GRAMMAR below)", which helps.

Isn't (4) also a subset of (1)?

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Proposed new feature for bash: unbuffered pipes

2020-04-23 Thread Andreas Schwab
See stdbuf(1).

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Command substitution before while loop

2020-04-01 Thread Andreas Schwab
On Apr 01 2020, Krystian Wojtas via Bug reports for the GNU Bourne Again SHell 
wrote:

> Making comments in pipes using command substitution is very helpful. 
> But there is syntax error it it is done just before while loop. Could it be 
> considered as bug?

Not a bug.  Reserved words are only recognized at the start of a
command, before any expansions.  For the same reason a compound command
cannot be preceded by redirections.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Filename Expansion bug

2020-01-09 Thread Andreas Schwab
On Jan 09 2020, Mickael KENIKSSI wrote:

> I understand this may not sound of primary importance for you since they
> are canonically equivalent, but sometimes what we really all care about is
> the path as a literal string (be it well- or ill-formed), and not the
> filesystem object it points to.

But filename expansion is not operating on literal strings, it is
operating on existing filesystem objects.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: Request For Enhancement - TID variable

2019-12-26 Thread Andreas Schwab
On Dez 26 2019, Eric S. Raymond wrote:

> RFE: bash should have a TID varuable that returns the vakue of gettid(2).

Bash doesn't use threads, so $TID will always be the same as $BASHPID.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: quote removal issues within character class

2019-11-09 Thread Andreas Schwab
On Nov 09 2019, L A Walsh wrote:

> On 2019/11/09 04:49, Robert Elz wrote:
>> There's also
>>
>>  The special characters '.', '*', '[', and '\\'
>>  (, , , and ,
>>  respectively) shall lose their special meaning within a bracket
>>  expression.
>>   
> 
> Is this really what the standard says, because '\\' is not a character, but
> 2 characters.  They could use "\\" but if a backslash is between single
> quotes, it loses its special meaning.

This is C notation, not shell notation.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Feature Request: Custom delimeter for single quotes

2019-11-01 Thread Andreas Schwab
On Nov 01 2019, Patrick Blesi wrote:

> The actual use case is taking a command from a Ruby script:
>
> https://github.com/braintree/runbook/blob/4a0f0770a8a2a7be135cf13ee435d981b5975a06/lib/runbook/helpers/tmux_helper.rb#L23
>
> `tmux send-keys -t #{target} #{_pager_escape_sequence} '#{command}' C-m`
>
> The user specifies the command they want to run as a Ruby string and it
> gets interpolated into the above string and then executed (The backticks in
> Ruby invoke the command in a subprocess and return the output as a string,
> #{} is string interpolation). As you can see, if the user-specified command
> has a single quote, it will break this command unless escaped.

Just shell-quote the characters in the interpolated string, as you need
to do anyway for the other interpolated strings.  Not doing this would
be a security bug waiting to happen.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: -e test description in the GNU Bash 5.0 man page from 7 December 2018

2019-10-21 Thread Andreas Schwab
On Okt 21 2019, Marco Ippolito wrote:

> In the GNU Bash 5.0 man page from 7 December 2018 the -e test is
> documented as such:
>
>    -e file
>   True if file exists.
>
> When "file" is a symlink name to a non-existing target, the -e test fails,
> and this may be surprising from just reading the documentation.

It also says:

   Unless otherwise specified, primaries that operate on files follow sym-
   bolic links and operate on the target of the link, rather than the link
       itself.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: Is this a bug by any chance?

2019-10-07 Thread Andreas Schwab
On Okt 07 2019, Greg Wooledge  wrote:

> x=(1 2 3 4 5 -n '/*' 'hello world')
> for z in "${x[@]}"; do
>   printf %s "$z"
> done
> echo

(IFS=; printf '%s\n' "${x[*]}")

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: bash sets O_NONBLOCK on pts

2019-10-02 Thread Andreas Schwab
On Okt 02 2019, Matteo Croce  wrote:

> It seems to me that bash restores the flag, cat prints an error when not:
>
> $ cat
> $
>
> the same is not true if running multiple commands:
>
> $ ./foo; cat
> cat: -: Resource temporarily unavailable
> $
>
> Why this different behaviour?

Because it's reset immediately before reading the next line with
readline.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Wrong command option in the manual examples

2019-09-23 Thread Andreas Schwab
On Sep 23 2019, Robert Elz  wrote:

> Date:Mon, 23 Sep 2019 12:29:18 +0300
> From:Ilkka Virta 
> Message-ID:  <59cf49b0-1292-b752-4fe8-8928fd558...@iki.fi>
>
>   | (as well the standard '-depth', somewhat confusingly)
>
> There is no real standard for this - NetBSD has deprecated the -depth
> operator (which never really was one) and replaced it by a -d option
> which makes much more sense (-depth never really was the right way to
> do it).

According to https://www.freebsd.org/cgi/man.cgi, find -d already
appeared in 4.3BSD, and -depth is much newer.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: [Patch] (tiny problem) bad short_doc for % command

2019-09-21 Thread Andreas Schwab
On Sep 21 2019, "Christopher Chittleborough"  
wrote:

> The command "help -s %" outputs
> %: job_spec [&]
> when it should output
> %: % job_spec [&]
> because the $SHORT_DOC for "%" in builtins/reserved.def is wrong.

A job spec already starts with %.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: leaks fd for internal functions but not external command

2019-07-23 Thread Andreas Schwab
On Jul 23 2019, Sam Liddicott  wrote:

> It got closed in the parent. The lsof is running for the parent, the main
> process. /bin/echo has quit before the lsof runs.

When you run an external command the redirection is performed in the
child.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: Unexpected result of array assignment

2019-07-18 Thread Andreas Schwab
On Jul 18 2019, Henning  wrote:

> On 18/07/2019 03:16, Darren 'Tadgy' Austin wrote:
>
>>  foo=(["key"]="${foo["key"]} value2")
>
> using eval shoud also succeed, even for older bash:
>
>   eval 'foo=(["key"]="'"${foo["key"]}"' value2")'

This will break if ${foo["key"]} contains any of $ ` " \ .

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: Combination of "eval set -- ..." and $() command substitution is slow

2019-07-16 Thread Andreas Schwab
On Jul 16 2019, Ilkka Virta  wrote:

> On 15.7. 20:49, Robert Elz wrote:
>
>>  printf '%s\n' "`printf %s "$i"`"
>>  printf '%s\n' "$(printf %s "$i")"
>>
>> aren't actually the same.   In the first $i is unquoted, in the second it is
>> quoted.   
>
> Huh, really? It looks to me like the first one treats $i as quoted too:
>
>  $ touch file.txt; i='123 *'
>  $ printf '%s\n' "`printf :%s: "$i"`"
>  :123 *:

It is not portable, see the autoconf manual:

... is not portable, since not all shells properly understand
`"`..."..."...`"', for example Solaris 10 ksh:

 $ foo="`echo " bar" | sed 's, ,,'`"
     ksh: : cannot execute
 ksh: bar | sed 's, ,,': cannot execute

Posix does not specify behavior for this sequence.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: built-in printf %f parameter format depend on LC_NUMERIC

2019-07-12 Thread Andreas Schwab
On Jul 12 2019, Chet Ramey  wrote:

> I assume this means that bc doesn't use strtod.

Of course not, strtod doesn't parse arbitrary precision numbers.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: `eval` pollutes the history when it runs "set -o history"

2019-06-11 Thread Andreas Schwab
On Jun 11 2019, Chet Ramey  wrote:

> Maybe. But the user-visible option that says whether or not to save
> commands in the history is decoupled from the internal set of flags that
> control it. The option should remain visibly on unless the user turns it
> off, even if saving commands in the history is temporarily suppressed. The
> thing is that enabling history with `set -o history' turns all of these
> things on.

But should the effect of `set -o history' be deferred until the end of
the temporary suppression?

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: Backslash mysteriously disappears in command expansion when unescaping would reference an existing file

2019-05-22 Thread Andreas Schwab
On Mai 22 2019, Charles-Henri Gros  wrote:

> The file name is the regex (argument to "-e"), not the file "grep"
> reads. I want to check that some text file contains a reference to a file.
>
> But it looks like this would work:
>
> for file in $(find ...); do grep -e "$(echo -n "$file" | sed 's/\$/\\$/g')" 
> someinput; done

Use grep -F instead.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Arithmetic expansion with increments and output redirection

2019-04-24 Thread Andreas Schwab
On Apr 24 2019, Greg Wooledge  wrote:

> On Wed, Apr 24, 2019 at 06:47:41AM -0600, Ian Neal wrote:
>> At what point is a subshell being invoked? There's no pipeline, command
>> substitution, coprocess, background process, or explicit () subshell here,
>> which are the only cases a subshell should be created. Otherwise, the
>> entire operation should be evaluated by the main shell. Arithmetic
>> expansion is not in that list.
>
> The context got snipped but IIRC it was something like
>
> /bin/true > $((n++))
>
> The /bin/true forces the use of an external command, which means a subshell
> is forked.  The redirection occurs in the forked subshell.

But the expansion isn't required to be performed in the subshell.  I
don't see POSIX having any wording to require one or the other.  Doing
the expansion before the fork looks reasonable, even if only to make it
consistent with builtins.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: "here strings" and tmpfiles

2019-04-11 Thread Andreas Schwab
On Apr 10 2019, Daniel Kahn Gillmor  wrote:

> data written to the local filesystem can be discovered by someone
> analyzing the disk controller data path, or by someone with access to
> the underlying storage medium.

Do you have swap enabled?

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: wait -n shouldn't collect multiple processes

2019-03-26 Thread Andreas Schwab
On Mär 26 2019, Ben Elliston  wrote:

> On Mon, Mar 25, 2019 at 04:53:02PM -0400, Chet Ramey wrote:
>
>> "wait  waits  for any job to terminate and returns its exit status"
>> 
>> Doesn't that imply a single job?
>
> Not as clearly as saying "wait waits for a single job to terminate"

Even better, IMHO: "wait waits for the next job to terminate"

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: Documentation consistency in the Arrays section

2019-02-21 Thread Andreas Schwab
On Feb 21 2019, Jeff Schaller  wrote:

> --- bashref.texi2019-02-21 09:10:12.0 -0500
> +++ bashref.texi.new2019-02-21 09:10:49.679101000 -0500
> @@ -7187,7 +7187,7 @@
>  @noindent
>  Associative arrays are created using
>  @example
> -declare -A @var{name}.
> +declare -A @var{name}
>  @end example

Perhaps it should be reformulated to avoid putting the example at the
end of the sentence.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: info missing in output of declare -a in 4.4.x

2019-02-18 Thread Andreas Schwab
On Feb 17 2019, Dennis Williamson  wrote:

> Oh, interesting! In Bash 4 and 5, I just did declare -p with no args and it
> showed BASH_ALIASES empty. But with declare -p BASH_ALIASES it shows the
> contents (as does the alias command).
>
> Other arrays that show this difference for me:
>
> BASH_CMDS
> DIRSTACK
> GROUPS
>
> Scalars that exhibit this issue:
>
> BASHPID
> BASH_COMMAND
> BASH_SUBSHELL
> COMP_WORDBREAKS
> HISTCMD
> LINENO
> RANDOM
> SECONDS

All these dynamic variables are displayed with values by declare -p
after the variable is accessed once.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: The use of register keyword in bash source code

2019-02-06 Thread Andreas Schwab
On Feb 06 2019, Peng Yu  wrote:

> If it is ignored anyway, why "register" is used in many places in the
> code? Thanks.

Because compilers were dumb in the old days.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: The use of register keyword in bash source code

2019-02-06 Thread Andreas Schwab
On Feb 06 2019, Peng Yu  wrote:

> I see many variables are declared with the "register" keyword. I know
> its purpose is to tell compile always access the corresponding memory
> without assuming the previously accessed values are preserved. This is
> usually to deal with some external devices.

No, that is what volatile means.  The register keyword is just an
optimisation hint, and is mostly ignored by the compiler.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: bug: illegal function name?

2019-01-20 Thread Andreas Schwab
On Jan 20 2019, Andrey Butirsky  wrote:

> |$ unset 1a ||
> ||bash: unset: `1a': not a valid identifier

Use `unset -f'.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: Regexp string in := parameter expansion triggers failglob

2019-01-08 Thread Andreas Schwab
On Jan 08 2019, polynomia...@gentoo.org wrote:

> Description:
>   When sourcing a script that contains a variable which performs
>   a := parameter expansion with a regular expression while failglob

At this point it is just a random string, not a regular expression, and
the fact that := is used is irrelevant.

>   shell option is enabled, bash-5.0 emits a "no match: " 

At this point it is a glob pattern, not a regexp.

>   echo ${TESTPATTERN}

If you don't want filename expansion, use quotes.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: A small documentation suggestion

2019-01-08 Thread Andreas Schwab
On Jan 07 2019, Keith Thompson  wrote:

> I suggest documenting this behavior. It would be nice to be able to
> depend on the exact format, for example that ${EPOCHREALTIME/*./}
> is always exactly 6 digits long.

ms=${EPOCHREALTIME/*./}00
ms=${ms:0:6}

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: Error on arithmetic evaluation of `~0`.

2018-12-20 Thread Andreas Schwab
On Dez 20 2018, Greg Wooledge  wrote:

> The issue you're reporting appears to be present in arithmetic contexts
> in general, not only arrays:
>
> wooledg:~$ echo $((~0))
> bash: /home/wooledg: syntax error: operand expected (error token is 
> "/home/wooledg")

This has been fixed in bash 5.0.

> It appears that bash is performing tilde expansion when there's no
> whitespace in front of the tilde, or bitwise negation if there is
> whitespace.

POSIX says that arithmetic expressions are not subject to tilde
expansion.  IMHO bash shouldn't do that either for indexed array
subscripts, since they are arithmetic expressions.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: Bash-5.0-beta2 available for download

2018-11-27 Thread Andreas Schwab
Index: bash-5.0-beta2/expr.c
===
--- bash-5.0-beta2.orig/expr.c
+++ bash-5.0-beta2/expr.c
@@ -342,7 +342,7 @@ expr_bind_variable (lhs, rhs)
 #if defined (ARRAY_VARS)
 /* This is similar to the logic in arrayfunc.c:valid_array_subscript when
you pass VA_NOEXPAND. */
-static char *
+static int
 expr_skipsubscript (vp, cp)
  char *vp, *cp;
 {

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



Re: A possible bug on autocompletion after setting FUNCNEST level

2018-10-08 Thread Andreas Schwab
On Okt 08 2018, Valentin Bajrami  wrote:

> This is some kind of a follow up on "Segfault on recursive trap/kill"
> reported by Mike Grewitz.
>
> After setting FUNCNEST and the listing a file or using 'vi filname[TAB]'  a
> bug is triggered.
>
> This is how I could reproduce this:
>
> f3d0r4:~/FOO# FUNCNEST=4
>
> f3d0r4:~/FOO# ls
> procps-ng-3.3.12-3.fc28.src.rpm
> procps-ng-3.3.12-pmap-all-lines-twice.patch  procps-ng-3.3.12.tar.xz
> procps-ng-3.3.14-CVE-2018-1124.patch  procps-ng.spec  README.md  README.top
>
> f3d0r4:~/FOO# vi pr-bash: __reassemble_comp_words_by_ref: maximum function
> nesting level exceeded (4)

In which way is this a bug?  AFAICT, FUNCNEST is doing its job.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: "Variation" in Command Substitution Behaviour

2017-02-28 Thread Andreas Schwab
On Feb 28 2017, Geoff Hull <gbh...@gmail.com> wrote:

> If I "source" the attached file (i.e. ". test_aliases") in a bash session,
> then run the following:
>
> assemble_fam1
> assemble_fam2
> say_families
>
> I see the following output:
>
> Flintstones=wilma:bam-bam:fred
> Rubbles=barney

It seems like the shell is eating an extra newline.  Try typing an empty
line after assemble_fam2:

$ set -x
$ assemble_fam1
+ fred
++ echo fred
+ FSTONES=fred
+ FSTONES=wilma:bam-bam:fred
$ assemble_fam2
+ barney
++ echo barney
+ RUBBLES=barney
$ 
+ RUBBLES=betty:pebbles:barney
$ say_families
+ say_families
+ echo Flintstones=wilma:bam-bam:fred
Flintstones=wilma:bam-bam:fred
+ echo Rubbles=betty:pebbles:barney
Rubbles=betty:pebbles:barney

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: null pointer deref, segfault

2017-01-24 Thread Andreas Schwab
On Jan 24 2017, "Brian 'geeknik' Carpenter" <brian.carpen...@gmail.com> wrote:

> <<$(()())|>_[$($(<<0)) crashes bash on Debian, Red Hat, FreeBSD, etc.

Worksforme with bash 4.4.

$ bash -c '<<$(()())|>_[$($(<<0))'
bash: line 1: warning: here-document at line 1 delimited by end-of-file (wanted 
`0')
bash: warning: here-document at line 0 delimited by end-of-file (wanted 
`$(()())')
bash: line 1: warning: here-document at line 1 delimited by end-of-file (wanted 
`0')
bash: warning: here-document at line 0 delimited by end-of-file (wanted `0')

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: possible in bash?: filter stderr of a prog & send filtered-output out on stderr leaving stdout untouched

2016-12-06 Thread Andreas Schwab
{ $prog 2>&1 >&3 | grep -v "$RE_filt" >&2; } 3>&1

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: Filename completion causes doubling of initial ':' character

2016-12-03 Thread Andreas Schwab
On Dez 03 2016, "Ravi (Tom) Hale" <r...@hale.ee> wrote:

> Description:
> 
> Given a filename called ':example'
> When the user enters 'command :' and hits 
> Then the completion of the filename gets a doubled colon, specifically:
> ':\:example'

Make sure you don't have any custom completion functions (run complete
-r) or non-default setting of COMP_WORDBREAKS.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: Not operator (~) fail on arithmetic expansion.

2016-11-28 Thread Andreas Schwab
On Nov 28 2016, John McKown <john.archie.mck...@gmail.com> wrote:

> Not replying for Chet, who will have the definitive answer, I will say that
> I, personally, think that is working as designed. ~ 0 (with space between)
> is definitely the "not" operator. But without the middle space, ~0, where
> there is a white space character in front of the tilde, looks to me like
> the normal "get the home directory for the following id" processing. Eg: ~0
> gets the home for the 0 user (same as ~user) whereas in "a~0", then tilde
> is simply a character. This is basically how ever other Bourne type shell
> seems to work.

In Bash, ~0 means the 0th entry of the directory stack, ie. $PWD.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: Why does bash use xmalloc?

2016-11-06 Thread Andreas Schwab
On Nov 06 2016, Peng Yu <pengyu...@gmail.com> wrote:

> My point is why bash terminates when it runs an external command that
> requires a large memory. Shouldn't bash return an exit code on behalf
> of the failed command and continue to the next command?

You have limited the amount of memory the shell itself can use, that has
nothing to do with the command you ran.  There is no way the shell can
continue in this situation, if it cannot allocate any memory at all.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: Bash 4.4 doesn't compile on GCC 5.2(easy steps to reproduce)

2016-09-16 Thread Andreas Schwab
On Sep 16 2016, Lilian Moraru <lilian.morar...@gmail.com> wrote:

> Hello,
>
> I tried to compile Bash 4.4 in Habitat(habitat.sh):
> https://github.com/habitat-sh/core-plans/tree/master/bash and it fails to
> compile with the following messages:
> ```
> gcc  -DPROGRAM='"bash"' -DCONF_HOSTTYPE='"x86_64"'
> -DCONF_OSTYPE='"linux-gnu"' -DCONF_MACHTYPE='"x86_64-unknown-linux-gnu"'
> -DCONF_VENDOR='"unknown"'
> -DLOCALEDIR='"/hab/pkgs/lilian/bash/4.4.0/20160916115954/share/locale"'
> -DPACKAGE='"bash"' -DSHELL -DHAVE_CONFIG_H   -I.
> -I/hab/pkgs/core/readline/6.3.8/20160729192706/include -I. -I./include

Your readline doesn't match.  You need to use the bundled library.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: heap-use-after-free in GNU Bash 4.4.0

2016-09-09 Thread Andreas Schwab
On Sep 09 2016, Franco Costantini <franco.costantini...@gmail.com> wrote:

> We tested this issue on Ubuntu 14.04.5 (x86_64) but other configurations
> could be affected. To reproduce it, compilation with Address Sanitizer is
> required:

valgrind also finds the same error.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: Possible Bug in Auto-Complete

2016-08-07 Thread Andreas Schwab
On Sa, Aug 06 2016, hungry.ra...@gmail.com wrote:

> Created a directory with the C equivalent "test\n\t\\ this"
>
> typing 
>
> cd test gives me a list of a single file
>
> test  ^I\ this
>
> but will not autocomplete.

Worksforme.  Make sure you are not using external completion scripts.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



a=$* -> crash

2016-07-27 Thread Andreas Schwab
(gdb) r
Starting program: /bin/bash -c a=\$\*

Program received signal SIGSEGV, Segmentation fault.
quote_string (string=string@entry=0x0) at subst.c:3940
3940  if (*string == 0)

diff --git a/subst.c b/subst.c
index 37d96f9..16ae3f0 100644
--- a/subst.c
+++ b/subst.c
@@ -8575,7 +8575,7 @@ param_expand (string, sindex, quoted, expanded_something,
  /* If we're not quoted but we still don't want word splitting, 
make
 we quote the IFS characters to protect them from splitting 
(e.g.,
 when $@ is in the string as well). */
- else if (quoted == 0 && ifs_is_set && (pflags & PF_ASSIGNRHS))
+ else if (temp != 0 && quoted == 0 && ifs_is_set && (pflags & 
PF_ASSIGNRHS))
{
  temp1 = quote_string (temp);
      free (temp);

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: Setting IFS='*' causes bash to freeze on tab completion

2016-07-02 Thread Andreas Schwab
"Ibrahim M. Ghazal" <img...@gmail.com> writes:

> After further investigation, the problem seems to be that when IFS is
> set to '*', case *) doesn't get executed. Is this the intended
> behavior?
>
> For example:
>
> IFS='*'; case "foo" in *) echo "got here";; esac
>
> doesn't print "got here".

The same issue exists for the other glob special characters ? [ ] .

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: Bash 4.4 SIGINT during command substitution (?) causes borked terminal

2016-05-17 Thread Andreas Schwab
Grisha Levit <grishale...@gmail.com> writes:

> My keyboard input is “1234567890”, which produces:
>
> bash-4.4$ 24580bash: 13679: command not found

Probably two processes competing for terminal input.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: Avoid asterisk expansion when it selects "everything"

2016-04-14 Thread Andreas Schwab
Mike Frysinger <vap...@gentoo.org> writes:

> On 14 Apr 2016 09:23, Andreas Schwab wrote:
>> Mike Frysinger <vap...@gentoo.org> writes:
>> > alternative idea: alias your rm/mv/etc... commands if you're worried
>> > about them.  it's not uncommon to do in ~/.bashrc or wherever:
>> >alias rm='rm -i'
>> 
>> That's the worst advice you can give.
>
> hyperbole much ?

No, I mean it.

>> If you lose the alias for whatever reason you get silent failure.
>
> you mean you get the status quo.  oh no!

If you depend on the safety net you lose.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: Avoid asterisk expansion when it selects "everything"

2016-04-14 Thread Andreas Schwab
Mike Frysinger <vap...@gentoo.org> writes:

> alternative idea: alias your rm/mv/etc... commands if you're worried
> about them.  it's not uncommon to do in ~/.bashrc or wherever:
>   alias rm='rm -i'

That's the worst advice you can give.  If you lose the alias for
whatever reason you get silent failure.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



4.4-rc1: readline wrapping error when prompt wraps around

2016-03-26 Thread Andreas Schwab
When $PS1 contains \[ \] and is longer than the line length then
readline miscounts the wrap coloumn.  For example, set PS1 like this:

PS1="\[$(tput bold)\]$(printf '%*s' $(stty size | awk '{print$2}') x)\[$(tput 
sgr0)\] "

This causes readline to wrap the input too early by the amount of hidden
characters inside \[ \].

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: bash 4.4-rc1 EXECIGNORE not fully working?

2016-03-19 Thread Andreas Schwab
Eric Blake <ebl...@redhat.com> writes:

> But I don't know whether bash is calling exec[lv] with a canonicalized
> name instead of exec[lv]p() with the kernel doing the lookup;

PATH searching is a pure user-space concept.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: bug when 'cd ..' to a directory who's parent has been deleted

2016-02-09 Thread Andreas Schwab
Linda Walsh <b...@tlinx.org> writes:

> You can't open a file handle on a file.  The fd comes from some

> OS call associating it with the file on disk (or some other connection).
  

You have to decide which sentence is true.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: bug when 'cd ..' to a directory who's parent has been deleted

2016-02-08 Thread Andreas Schwab
Linda Walsh <b...@tlinx.org> writes:

> Um...Not exactly.  As long as there's a handle open to the previous path,
> it still exists (at least on linux and unix).

You cannot have handles on file names, only on files.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: bug when 'cd ..' to a directory who's parent has been deleted

2016-02-08 Thread Andreas Schwab
Chet Ramey <chet.ra...@case.edu> writes:

> It's still an unlikely scenario.

What do you mean with unlikely?  Removing some directory where there is
still a shell active can happen all the time.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: bug when 'cd ..' to a directory who's parent has been deleted

2016-02-08 Thread Andreas Schwab
Chet Ramey <chet.ra...@case.edu> writes:

> On 2/8/16 9:59 AM, Andreas Schwab wrote:
>> Chet Ramey <chet.ra...@case.edu> writes:
>> 
>>> `cd ..' should fail, since the parent no longer exists, and the pathname
>>> canonicalization should fail, since there's presumably no longer a valid
>>> path to reach the current directory.  No value for $PWD is correct.
>> 
>> ${PWD%/*} would be a reasonable value.  FWIW, this is what ksh uses in
>> this case, it doesn't fail.
>
> Why would that be more reasonable than anything else?  It references a
> path that doesn't exist.

Sorry, I misread the OP's message.  I didn't notice it's about the
parent's parent, not the parent.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: bug when 'cd ..' to a directory who's parent has been deleted

2016-02-08 Thread Andreas Schwab
Chet Ramey <chet.ra...@case.edu> writes:

> If you assume, as the OP said, that only the parent is removed, it's
> unlikely.

You cannot remove a non-empty directory, so this does not make sense.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: bug when 'cd ..' to a directory who's parent has been deleted

2016-02-08 Thread Andreas Schwab
Chet Ramey <chet.ra...@case.edu> writes:

> `cd ..' should fail, since the parent no longer exists, and the pathname
> canonicalization should fail, since there's presumably no longer a valid
> path to reach the current directory.  No value for $PWD is correct.

${PWD%/*} would be a reasonable value.  FWIW, this is what ksh uses in
this case, it doesn't fail.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: Security Vulnerability

2016-02-07 Thread Andreas Schwab
Rakesh Mane <rakeshmane12...@gmail.com> writes:

> In real life, if an attacker founds a command injection vulnerability in
> some system then he can use this flaw to bypass filters or waf's by simply
> uploading a file having a command as filename (example: reboot) and then by
> sending "*" as command.

Sending arbitrary commands to a shell is a security bug, but not a bug
in the shell which is working as designed.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: Leak in BASH "named" file descriptors?

2016-01-28 Thread Andreas Schwab
Mathieu Patenaude <mpatena...@gmail.com> writes:

> The issue I see with relying on the bash EXIT to actually have the system
> do the cleanup is when you have a script that does things in a forever
> loop, you end up with FD exhaustion when using "named" FD and here strings.

Of course, if you don't close (or reuse) your descriptors you will run
out of them eventually.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: Leak in BASH "named" file descriptors?

2016-01-28 Thread Andreas Schwab
Greg Wooledge <wool...@eeg.ccf.org> writes:

> On Wed, Jan 27, 2016 at 01:18:11PM -0500, Mathieu Patenaude wrote:
>> When using "named" file descriptors inside a function, the file descriptors
>> are not automatically un-linked when the function returns, but when using
>> regular "numbered" file descriptors they are automatically "destroyed".
>
> Could not reproduce in an interactive shell, on bash 4.3.30 (Debian).
>
> $ f() { local fd; exec {fd} $ f
> $ g() { exec 9 $ g
> $ lsof -p $$
> ...
> bash931 wooledg0u   CHR  136,0  0t0   3 /dev/pts/0
> bash931 wooledg1u   CHR  136,0  0t0   3 /dev/pts/0
> bash931 wooledg2u   CHR  136,0  0t0   3 /dev/pts/0
> bash931 wooledg9r   CHR1,3  0t01028 /dev/null
> bash931 wooledg   10r   CHR1,3  0t01028 /dev/null
> bash931 wooledg  255u   CHR  136,0  0t0   3 /dev/pts/0
>
> I actually ran the lsof multiple times, in between the calls to f and g.
> FD 10 was opened by f (and kept open), and FD 9 was of course opened by g
> (and kept open).

Try replacing exec with :.  Redirections established with exec are
always permanent.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: implicit redirection of background within pipeline

2016-01-13 Thread Andreas Schwab
Martin Kealey <mar...@kurahaupo.gen.nz> writes:

> The standard is actually a bit vague; under "Compound Commands" it mentions
> that "Each redirection will apply to all the commands within the compound
> command that do not explicitly override that redirection" but it fails to
> mention that this applies to pipes as well; so I submit that it is a
> reasonable interpretation that a pipe on an outer block counts as an
> (explicit) redirection for the purpose of reading the "Asynchronous Lists"
> sub section.

I don't think so.
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_07
doesn't mention pipelines.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: implicit redirection of background within pipeline

2016-01-13 Thread Andreas Schwab
Martin Kealey <mar...@kurahaupo.gen.nz> writes:

> What do other shells do? Ksh? Dash? Zsh?

$ ksh -c 'printf "foo1\nfoo2\n" | { (read x; echo 1: $x) & (read x; echo 2: $x) 
& }'
1: foo1
2: foo2
$ dash -c 'printf "foo1\nfoo2\n" | { (read x; echo 1: $x) & (read x; echo 2: 
$x) & }'
1:
2:
$ zsh -c 'printf "foo1\nfoo2\n" | { (read x; echo 1: $x) & (read x; echo 2: $x) 
& }'
1: foo1
2: foo2
$ bash -c 'printf "foo1\nfoo2\n" | { (read x; echo 1: $x) & (read x; echo 2: 
$x) & }'
1:
2: foo1

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: implicit redirection of background within pipeline

2016-01-13 Thread Andreas Schwab
Martin Kealey <pg...@google.com> writes:

> On 13 Jan 2016 8:14 p.m., "Andreas Schwab" <sch...@suse.de> wrote:
>
>> I don't think so.
>>
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_07
>> doesn't mention pipelines.
>
> That was rather my point. Given that they aren't mentioned, one has to take
> them as read,

What does "take them as read" mean?

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: implicit redirection of background within pipeline

2016-01-11 Thread Andreas Schwab
Chet Ramey <chet.ra...@case.edu> writes:

> On 1/10/16 12:54 PM, Piotr Grzybowski wrote:
>> hey,
>> 
>>  I am quite sure it happens here (devel branch, at
>> 6f82653c5ef09aeeeba4376a1c65ce86c3605c00):
>> 
>> execute_cmd.c +5115:
>>if ((cmdflags & CMD_STDIN_REDIR) &&
>>   pipe_in == NO_PIPE &&
>>   (stdin_redirects (redirects) == 0))
>>  async_redirect_stdin ();
>> 
>>  but after reading the comments some 3.5k lines earlier I am not sure
>> how to fix it; of course commenting out the if in
>> execute_cmd.c:5112-5115 solves it, but who can tell what it breaks?
>
> Posix requires this behavior:
>
> "The standard input for an asynchronous list, before any explicit
> redirections are performed, shall be considered to be assigned to a file
> that has the same properties as /dev/null."

But isn't it a bug that subsequent asynchronous commands in the list are
not redirected from /dev/null?

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: doesn't bash do variable subst. or quote removal on function statement

2016-01-10 Thread Andreas Schwab
Linda Walsh <b...@tlinx.org> writes:

>>  shopt -s expand_aliases; alias my=declare
>>  declare fn=myfunc## function name in variable 
> doesn't work
>>  function $fn { echo $fn ; }
> -bash: `$fn': not a valid identifier
>>my -pf myfunc
> -bash: declare: myfunc: not found
>>
>>  def="function $fn () { echo $fn ; }"  ## but same statement, eval'd works

That's not the same statement.  The same statement would be

def='function $fn () { echo $fn ; }'

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: Feature: Easily remove current command from history

2016-01-04 Thread Andreas Schwab
Victor Porton <por...@narod.ru> writes:

> It should be easy to remove lines with passwords and potentially
> harmful commands (like sudo with rm).

C-a C-k

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: ${1+"$@"} does not generate multiple words if IFS is empty

2015-12-30 Thread Andreas Schwab
mart...@inlv.org writes:

>   The substitution ${1+"$@"} should resolve to "$@" if there is at
>   least one parameter -- i.e. one word per parameter. This works fine
>   if IFS contains any character or is unset. If IFS is empty, it
>   instead resolves to the equivalent of "$*", i.e. a single word
>   concatenating all the parameters without a separator. IFS should
>   not influence the behaviour of "$@" under any circumstances.

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05

"If the value of IFS is null, no field splitting shall be performed."

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: rewriting a readonly var should exit

2015-12-15 Thread Andreas Schwab
Aurelien ROUGEMONT <be...@gandi.net> writes:

> Description:
>   in the posix shell specification [1] when a script tries to to
> overwrite a readonly variable it should crash the script.
>
> Repeat-By:
> #!/bin/bash
> readonly rovar="goodvalue"
> rovar="badvalue"
>   echo "You should not see this message"

You are not running the shell in posix mode.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: Bug in bash 4.4-beta: suspending and restarting "man" program

2015-11-11 Thread Andreas Schwab
Keith Thompson <keithsthomp...@gmail.com> writes:

> On Tue, Nov 10, 2015 at 1:57 PM, Andreas Schwab <sch...@linux-m68k.org>
> wrote:
>
>> Chet Ramey <chet.ra...@case.edu> writes:
>>
>> > I can make bash blow away the original signal dispositions and pretend
>> they
>> > were SIG_DFL when an interactive shell starts, if there is no
>> alternative.
>>
>> Given that login(1) has the same behaviour there is probably no
>> alternative.
>>
>> Hmm. I just tried bash 4.4-beta on a Linux console (Ctrl-Alt-F1), and
> Ctrl-Z works correctly.
> I verified that the shell's parent process was "login".
> Perhaps (at least the Debian version of) login(1) *doesn't* do that.

FreeBSD's login does it too.

<https://svnweb.freebsd.org/base/head/usr.bin/login/login.c?revision=287634=markup#l649>

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: Proposed Prompt Escapes

2015-11-10 Thread Andreas Schwab
Dennis Williamson <dennistwilliam...@gmail.com> writes:

> But wait, you don't need the intermediate step! It already works!!!
>
> prompt=$'\u, something about dominoes \U1F061  \@ '

You should quote the backslashes.

prompt=$'\\u, something about dominoes \U1F061  \\@ '

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: Bug in bash 4.4-beta: suspending and restarting "man" program

2015-11-10 Thread Andreas Schwab
Chet Ramey <chet.ra...@case.edu> writes:

> I can make bash blow away the original signal dispositions and pretend they
> were SIG_DFL when an interactive shell starts, if there is no alternative.

Given that login(1) has the same behaviour there is probably no
alternative.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: Out of bounds heap read in function rl_tilde_expand

2015-11-06 Thread Andreas Schwab
Hanno Böck <ha...@hboeck.de> writes:

> Triggering this bug only seems to work with a US keyboard layout. It
> gets triggered by pressing shift+alt+7.
> I don't know why this is happening, this keycode combination doesn't
> have any function on an us keyboard.

This is generating M-& of course, which is bound to tilde-expand.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: loadable builtins on HP-UX

2015-11-04 Thread Andreas Schwab
Greg Wooledge <wool...@eeg.ccf.org> writes:

> The linker option in HP-UX 11.11 is -E .

FWIW, GNU ld also accepts this as a synonym for -rdynamic.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



  1   2   3   4   5   6   >