Re: Revisiting Error handling (errexit)

2022-07-08 Thread Greg Wooledge
On Fri, Jul 08, 2022 at 01:52:04PM +0300, Yair Lenga wrote: > While you can achieve results similar to 'errfail' with existing bash > commands (you will need more than && !), the required effort is not > practical: > * Consider a common scenario (for me) - a script with 1000 lines, complex > logic,

Re: reporting a bug: output of a long line, longer than fits on winow-size, breakes bash

2022-07-10 Thread Greg Wooledge
On Sun, Jul 10, 2022 at 02:35:40PM +0200, Anton Wessel wrote: > When a one-liner is long, longer than fits on current window size, then > problems in bash occure. > > This has nothing to do with what is the contents of the long line. > > Bash is broken by the fact that window size is exceeded. >

Re: [the result of $[23**15] is wrong]

2022-07-11 Thread Greg Wooledge
On Mon, Jul 11, 2022 at 10:14:12PM +0800, root@ROCKY8-5-WL.localdomain wrote: > [Detailed description of the problem, suggestion, or complaint.] > in bash the result of $[23**15] is wrong > for example output > [root@ROCKY8-5-02 ~]#echo $[23**15] > 8380818432457522983 > [root@ROCKY8-5-02 ~]#e

Re: [the result of $[23**15] is wrong]

2022-07-11 Thread Greg Wooledge
On Mon, Jul 11, 2022 at 10:41:40PM +0700, Robert Elz wrote: > Should we be attempting to reply to root@ROCKY8-5-WL.localdomain ? > > I'm not going to bother. Same. > ps: Isn't $[ supposed to be obsolete? It's deprecated and undocumented. But Chet never removed the actual code, presumably in or

Re: functions can fully unset local vars in other scopes

2022-07-28 Thread Greg Wooledge
On Fri, Jul 29, 2022 at 03:59:07AM +0200, Emanuele Torre wrote: > This enables defininng a "really_unset" function like so: > > really_unset () { unset "$@" ;} > > Which may be useful I guess. https://lists.gnu.org/archive/html/bug-bash/2010-05/msg00045.html https://fvue.nl/wiki/Bash:

Re: 5.1 regression?

2022-08-01 Thread Greg Wooledge
On Mon, Aug 01, 2022 at 04:37:18PM +0900, Dominique Martinet wrote: > Harald Dunkel wrote on Mon, Aug 01, 2022 at 09:08:40AM +0200: > > a colleague pointed me to a changed behavior of bash 5.1.4 in Debian 11. > > > > #! /bin/bash > > # set -x > > > > insert() > > { > >local data="$1" > >

Re: Arithmetic expression: recursive VAR evaluation suppresses desired VAR assignment

2022-08-11 Thread Greg Wooledge
On Thu, Aug 11, 2022 at 04:04:57PM +0200, Steffen Nurpmeso wrote: > Hm. Well i agree that precedence rules which loose a construct > completely (in that =5 is lost in I=5?I:J) is weird, but other What's that even supposed to *be*? You're assigning I=5 and then checking whether the assignment act

Re: How come math/arithmetic cannot work by set -x

2022-08-12 Thread Greg Wooledge
On Sat, Aug 13, 2022 at 06:51:04AM +0700, Budi wrote: > It doesn't work means no use on set -x, no value is shown set -x shows the command being executed, with arguments expanded. unicorn:~$ cat foo #!/bin/bash set -x a=5 b=7 c=$((a * b)) echo "$c" unicorn:~$ ./foo + a=5 + b=7 + c=35 + echo 35

Re: Performances comparission between 5.1 and 5.2.

2022-08-15 Thread Greg Wooledge
On Mon, Aug 15, 2022 at 07:05:49PM +0200, felix wrote: > Description: > Trying some script under 5.2 beta, rc1 and rc2, I was surprised by > execution time. Pre-release versions of bash are built with extra debugging stuff, and will not perform like full-release versions.

Re: Bash Coding style - Adopting C99 declarations

2022-08-28 Thread Greg Wooledge
On Sun, Aug 28, 2022 at 10:47:38AM -0400, Yair Lenga wrote: > Hi, > > I've noticed Bash code uses "old-style" C89 declarations: > * Parameters are separated from the prototype > * Variables declared only at the beginning of the function > * No mixed declaration/statements > * No block local variab

Re: Light weight support for JSON

2022-08-28 Thread Greg Wooledge
On Sun, Aug 28, 2022 at 08:47:24PM -0400, Dale R. Worley wrote: > The "obvious" way to support Json in Bash would be a utility that parses > Json and produces e.g. a Bash associative array, and conversely a > utility that reads a Bash associative array and produces Json. The real > limitation is t

Re: test or [ does not handle parentheses as stated in manpage

2022-09-05 Thread Greg Wooledge
On Mon, Sep 05, 2022 at 09:55:29PM +0100, Julian Gilbey wrote: > if [ ("$1" = "yes" -o "$1" = "YES") -a ("$2" = "red" -o "$2" = "RED") ] You're doing it wrong. The parentheses have to be quoted, and separate. [ "(" "$1" = yes" -o "$1" = YES" ")" -a ... ] I'd strongly recommend that you DON'T do

Re: Parameter expansion with extended pattern make system hang

2022-09-06 Thread Greg Wooledge
On Tue, Sep 06, 2022 at 11:55:52AM -0400, Chet Ramey wrote: > On 9/4/22 10:48 PM, Hyunho Cho wrote: > > > Bash Version: 5.1 > > Patch Level: 16 > > Release Status: release > > > > ## > > > > > > "gcc --help" is already a short str

Re: Parameter expansion with extended pattern make system hang

2022-09-06 Thread Greg Wooledge
On Tue, Sep 06, 2022 at 10:11:00PM +0200, Martin Schulte wrote: > Hi! > > > Running with this assumption, now that we know bash's extglob matching > > will not perform suitably for this task, we can look at other approaches. > > Here's another: > > printf -- '%s ' $(gcc --help) | sed 's/ $/\n/'

Re: read problem

2022-09-24 Thread Greg Wooledge
On Sun, Sep 25, 2022 at 03:44:35AM +0700, Robert Elz wrote: > (in this message, \s represents a space, just for clarity - \s meaning space > cannot be used in shells, any of them, anywhere) Just for the record, if \s appears in the regex on the right hand side of =~ in bash's [[ $string =~ $regex

Re: declare -F incorrect line number

2022-10-06 Thread Greg Wooledge
On Fri, Oct 07, 2022 at 01:28:59AM +1000, Martin D Kealey wrote: > I write nested functions quite often, usually with a subsequent `unset -f` > but sometimes (necessarily) without. > > Being able to write `local -F funcname { ... }` or `function -L funcname { > ... }` would be a nice replacement f

Re: bash core dumps doing glob pattern on long string

2022-10-11 Thread Greg Wooledge
On Tue, Oct 11, 2022 at 12:38:44PM -0700, Koichi Murase wrote: > As far as I know, glob/extglob > does not have constructs that cannot be represented by formal regular > languages so should always be able to be represented by NFAs and thus DFAs. It's been too many decades since I studied this stuf

Re: -v no longer works for associative arrays

2022-10-13 Thread Greg Wooledge
On Thu, Oct 13, 2022 at 10:42:02AM -0400, Bryan Roessler wrote: > Description: > > bash-5.2# declare -A a > bash-5.2# a[foo]=bar > bash-5.2# [[ -v a[@] ]]; echo $? > 1 > > bash-5.1# declare -A a > bash-5.1# a[foo]=bar > bash-5.1# [[ -v a[@] ]]; echo $? > 0 > > If this is by design I missed it.

Re: -v no longer works for associative arrays

2022-10-13 Thread Greg Wooledge
On Thu, Oct 13, 2022 at 02:35:55PM -0400, Chet Ramey wrote: > On 10/13/22 12:47 PM, Bryan Roessler wrote: > > For indexed arrays, yes. I hadn't made the connection with associative > > arrays since I don't typically index them with numbers, thanks. > > There has to be some default, and "0" is at l

Re: bash "extglob" needs to upgrade at least like zsh "kshglob"

2022-10-28 Thread Greg Wooledge
On Fri, Oct 28, 2022 at 03:44:34PM +0900, Hyunho Cho wrote: > # this is just for testing purposes. > $ foo=$( gcc -v --help 2> /dev/null | sed -En 's/^\s*(-[^ ]+).*/\1/p' ) The last time this issue was reported, we mentioned that "gcc --help" is not a standard document that appears the same on eve

Re: bash "extglob" needs to upgrade at least like zsh "kshglob"

2022-10-29 Thread Greg Wooledge
On Sat, Oct 29, 2022 at 04:50:00PM +1100, Martin D Kealey wrote: > This seems like a good reason to simply translate extglobs into regexes, > which should run in linear time, rather than put effort into building and > debugging a parallel implementation. This isn't straightforward, because of the

Re: Multiline editing breaks if the previous output doesn't end in newline

2022-10-30 Thread Greg Wooledge
On Mon, Oct 31, 2022 at 03:40:34AM +0200, Oğuz wrote: > > Option B: Fix the line editor to take into account when the > > prompt doesn't start at column 0. > > > > > Yeah, or add a new prompt sequence (e.g. \N) that prints a newline only if > the cursor is not at column 0. There's no 100%

Re: bash "extglob" needs to upgrade at least like zsh "kshglob"

2022-10-31 Thread Greg Wooledge
On Mon, Oct 31, 2022 at 05:00:40AM +0200, Oğuz wrote: > 31 Ekim 2022 Pazartesi tarihinde Martin D Kealey > yazdı: > > If we use the standard POSIX BRE or ERE, then there's no additional code to > > ship; it's included as part of the OS. The hard part is what to do with > > (!LIST), which was the p

Re: local/typeset/declare -p - outputs invalid declare -- -

2022-10-31 Thread Greg Wooledge
On Mon, Oct 31, 2022 at 06:12:14PM +0100, Alex fxmbsw7 Ratchev wrote: > hi , sorry.. whats the purpose of local - > informational question a. Since there is no `declare -' equivalent of `local -', make sure to use `local -' in the output of `local -p'. - s. The `local' builtin takes a ne

Re: string substitution broken since 5.2

2022-11-03 Thread Greg Wooledge
On Fri, Nov 04, 2022 at 03:31:44AM +0900, Koichi Murase wrote: > 2022年11月4日(金) 2:50 Andreas Schwab : > > On Nov 03 2022, thierryb--- via Bug reports for the GNU Bourne Again SHell > > wrote: > > > Description: > > > String substitution code running for years is broken in 5.2. > > > > > > Rep

Re: string substitution broken since 5.2

2022-11-03 Thread Greg Wooledge
On Fri, Nov 04, 2022 at 04:09:10AM +0900, Koichi Murase wrote: > When one wants to also support Bash 4.2, one possible workaround is to > assign the result to a variable (without quoting the right-hand side > of the assignment): > > $ bash-4.2 -c 'string=\"hi\"; string=${string//\"/\"}; echo "$str

Re: string substitution broken since 5.2

2022-11-03 Thread Greg Wooledge
On Thu, Nov 03, 2022 at 05:20:52PM -0400, Greg Wooledge wrote: > On Fri, Nov 04, 2022 at 04:09:10AM +0900, Koichi Murase wrote: > > When one wants to also support Bash 4.2, one possible workaround is to > > assign the result to a variable (without quoting the right-hand side > &

Re: string substitution broken since 5.2

2022-11-04 Thread Greg Wooledge
On Fri, Nov 04, 2022 at 09:50:03AM +0100, Alex fxmbsw7 Ratchev wrote: > On Fri, Nov 4, 2022, 08:56 Léa Gris wrote: > > > Le 03/11/2022 à 19:50, Chet Ramey écrivait : > > > The option is enabled by default. If you want to restore the previous > > > behavior, add `shopt -u patsub_replacement'. > >

Re: string substitution broken since 5.2

2022-11-04 Thread Greg Wooledge
On Fri, Nov 04, 2022 at 01:30:16PM +0100, Alex fxmbsw7 Ratchev wrote: > > 1) Put something like "shopt -u patsub_replacement 2>/dev/null || true" > >at the top of your script. > > > > there d be many such senselessnesses > > > > > 2) Assign the result of the expansion to a temporary variable,

Re: [bash 4] 'test -v 1' is never true

2022-11-25 Thread Greg Wooledge
On Fri, Nov 25, 2022 at 03:40:42PM -0600, G. Branden Robinson wrote: > I don't think it is a bug. It is unspecified behavior according to > POSIX. > > "-v" is not an operator according to POSIX, and I don't recall seeing it > in any shell. It is therefore interpreted as a string argument. [...]

Re: [bash 4] 'test -v 1' is never true

2022-11-25 Thread Greg Wooledge
On Sat, Nov 26, 2022 at 10:09:22AM +0700, Robert Elz wrote: > My preferred method for this, which works for all kinds > of variables and parameters is > > test "${X+s}" = s > > where X is whatever is to be tested (1 in this case) > and "s" is any string you like, except "" .. must be > the

Re: Bad leaks file fd to child processes

2022-11-28 Thread Greg Wooledge
On Mon, Nov 28, 2022 at 05:00:28PM -0500, Dale R. Worley wrote: > Alexey via Bug reports for the GNU Bourne Again SHell > > Same behavior was in bash 4.4 (as well as now in bash 5.2): > > > > # echo $BASH_VERSION > > 4.4.0(1)-release > > # exec 66 > # pvs > > File descriptor 66 (/etc/hosts) leaked

Re: declare XXX=$(false);echo $?

2022-12-02 Thread Greg Wooledge
On Fri, Dec 02, 2022 at 11:28:50AM +0100, Ulrich Windl wrote: > Surprisingly "declare XXX=$(false);echo $?" outputs "0" (not "1") https://mywiki.wooledge.org/BashPitfalls#pf27

Re: Handling files with CRLF line ending

2022-12-03 Thread Greg Wooledge
On Sat, Dec 03, 2022 at 05:40:02AM -0500, Yair Lenga wrote: > I was recently asked to deploy a bash/python based solution to windows > (WSL2). The solution was developed on Linux. Bash is being used as a glue > to connect the python based data processing (pipes, files, ...). Everything > works as

Re: reporting a bug

2022-12-15 Thread Greg Wooledge
On Thu, Dec 15, 2022 at 10:55:51AM +, y...@liberman.co.il wrote: > function sa { > for y in $(seq $1 $e2); do > echo "echo search $y " > done > } As others have pointed out, you've written $e2 instead of $2. In addition to that, you're relying on the Linux-speci

Re: printf %n is not documented

2022-12-23 Thread Greg Wooledge
On Fri, Dec 23, 2022 at 06:53:08PM -0500, Chet Ramey wrote: > On 12/23/22 7:24 AM, Emanuele Torre wrote: > > About two months ago, I discovered, reading the bash source code for > > printf, the %n format specifier. > > > > What it does is assign to the variable specified as its argument, the > > n

Re: Read Prompt Width Miscalculation (Non-Printing Characters)

2022-12-28 Thread Greg Wooledge
On Wed, Dec 28, 2022 at 01:09:02PM -0600, The Administrator wrote: > Hello and happy holiday hacking. Does the read builtin stand to benefit > from \[ and \] denotation ala $PS1 and friends? Here is a quick example: > > > read -erp "$( tput setaf 2 )NEW:$( tput sgr0 ) " > > Fill the line with “

Re: Arithmetic expression: evaluation order bug

2022-12-29 Thread Greg Wooledge
On Fri, Dec 30, 2022 at 12:21:52AM +0100, Steffen Nurpmeso wrote: > ..i want to reiterate the relation to what "human logic" expects. I'm a human, so I feel qualified to address this point. What I expect from a command like (( i += j += i += j )) is to get unpredictable results that have no rel

Re: Having an alias and a function with the same name leads to some sort of recursion

2023-01-02 Thread Greg Wooledge
On Mon, Jan 02, 2023 at 10:13:28AM +0200, Yuri Kanivetsky wrote: > Hi, > > #!/usr/bin/env bash > set -eu > alias cmd=echo Aliases are not used in bash scripts, unless bash is invoked in POSIX compatibility mode, or the "expand_aliases" shopt is turned on.

Re: Errors are ignored with local variable assignment

2023-01-04 Thread Greg Wooledge
On Wed, Jan 04, 2023 at 12:21:27AM -0600, Carlos Prieto López wrote: > Description: > Errors are ignored when a command with error is assigned to a local > variable on the same line of declaration. > > f(){ > return 1 > } > > g(){ > local v=`f` > } > g && echo g > the output is 'g', but

Re: UBSAN error in lib/sh/random.c:79

2023-01-06 Thread Greg Wooledge
On Sat, Jan 07, 2023 at 01:37:30AM +, Sam James wrote: > $ cat /tmp/guess_suffix > guess_suffix() { > tmpdir="${TMPDIR}"/.ecompress$$.${RANDOM} > } > guess_suffix > $ export UBSAN_OPTIONS="print_stacktrace=1:halt_on_error=1" > $ bash -x /tmp/guess_suffix > + guess_suffix > random.c:79:

Re: UBSAN error in lib/sh/random.c:79

2023-01-07 Thread Greg Wooledge
On Fri, Jan 06, 2023 at 09:00:30PM -0500, Greg Wooledge wrote: > On Sat, Jan 07, 2023 at 01:37:30AM +, Sam James wrote: > > random.c:79:21: runtime error: signed integer overflow: 31789 * 127773 > > cannot be represented in type 'int' > > #0 0x559791a301ce i

Re: UBSAN error in lib/sh/random.c:79

2023-01-07 Thread Greg Wooledge
On Sat, Jan 07, 2023 at 07:08:06PM +0100, Andreas Schwab wrote: > On Jan 07 2023, Greg Wooledge wrote: > > > I think this patch might be correct: > > > > > > --- lib/sh/random.c.orig2023-01-07 12:26:09.049950519 -0500 > > +++ lib/sh/random.c 2023-01-07 1

Re: UBSAN error in lib/sh/random.c:79

2023-01-10 Thread Greg Wooledge
On Sat, Jan 07, 2023 at 01:42:20PM -0500, Greg Wooledge wrote: > Or should the code do the multiplications with unsigned > values, store them in unsigned variables, and then replace the subtraction > with some kind of conditional that checks which of the two is greater? Here's a ver

Re: Next word of alias to alias that end with is not checked for alias

2023-01-12 Thread Greg Wooledge
On Thu, Jan 12, 2023 at 03:43:15AM +, anonymous4feedb...@outlook.com wrote: > Dear dir or madam, > > For the following script: > alias a1='echo ' > alias a2=a1 > alias foo=bar > a2 foo > bash outputs ‘foo’, instead of ‘bar’. > > GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu) on arc

Re: Next word of alias to alias that end with is not checked for alias

2023-01-12 Thread Greg Wooledge
On Fri, Jan 13, 2023 at 01:59:55AM +0700, Robert Elz wrote: > Date:Thu, 12 Jan 2023 10:56:33 -0500 > From:Chet Ramey > Message-ID: <0f03dd45-3e1a-54b1-f884-d3fb2c1c7...@case.edu> > > | Bash has never extended the `expand next word' semantics to multiple-level > |

Re: BASH_XTRACEFD=1 read variable stdout flushing?

2023-01-16 Thread Greg Wooledge
On Mon, Jan 16, 2023 at 11:36:18AM -0600, dave.dram...@gmail.com wrote: > hence `set -x`, but I want the output to go to stdout rather than > stderr so > that cron emails me only when there is an actual failure. With this Cron sends email if there's any output on either stdout or stde

Re: Next word of alias to alias that end with is not checked for alias

2023-01-17 Thread Greg Wooledge
On Wed, Jan 18, 2023 at 02:45:29AM +0100, alex xmb ratchev wrote: > aliases are major essential part of functionality Disagree. > that u cant , and speak against , all the time , is only enemish nonsense Don't worry. They're not going anywhere. They're shit, but you will still be allowed to pl

Re: [Suggestion] Flush command history to a "backup" file periodically

2023-01-19 Thread Greg Wooledge
On Fri, Jan 20, 2023 at 12:08:36AM +, Peter wrote: > Currently, in the event bash or something below it crashes, that > session's command history is lost. > It would be nice if bash saved it somewhere periodically, it doesn't > have to be too often, let's say on every second command. History m

Re: Segmentation Fault in bash --posix

2023-01-20 Thread Greg Wooledge
On Fri, Jan 20, 2023 at 11:50:52PM +0100, Martin Schulte wrote: > Hello Nicolas! > > > bash-5.1$ echo () { echo test } > > > echo test > > > } > > bash-5.1$ echo > Most probably you want to insert a ; before the first closing }: > > echo() { echo test ; } > > But even now bash w

Re: SIGINT handling during async functions

2023-01-21 Thread Greg Wooledge
On Sat, Jan 21, 2023 at 01:55:27PM +0100, Tycho Kirchner wrote: > cmd1 & > cmd2 & > wait > > If the user having launched this script from the interactive terminal aborts > it by hitting Ctrl+C, by default, the shell sends SIGINT to the process group > (pgid) of the script. However, while cmd1 an

Re: More convenient tracing

2023-01-25 Thread Greg Wooledge
On Wed, Jan 25, 2023 at 03:00:27PM -0500, Dale R. Worley wrote: > > Tracing with -x prints a lot of (usually) useless lines. > > $ bash -x ./tt > [300+ lines of Bash initializations] > + echo 'Now in tt.' > Now in tt. Why does it do this? Have you got BASH_ENV set to something i

Re: More convenient tracing

2023-01-26 Thread Greg Wooledge
On Thu, Jan 26, 2023 at 12:03:08PM -0500, Dale R. Worley wrote: > I do have BASH_ENV set, to ~/.bashrc. I need that so that my scripts > can use my .bashrc customizations. I strongly advise against this. All of the things a script does should be discoverable by reading the script, and any files

Re: unset does not remove functions like a[b] unless -f is specified

2023-02-02 Thread Greg Wooledge
On Thu, Feb 02, 2023 at 04:47:34PM +1000, Martin D Kealey wrote: > > ...in posix mode, fname must be a valid shell name and may not be the name > > of one of the POSIX special builtins. > > In default mode, a function name can be any unquoted shell word that does > > not contain $. ... > > I'm gu

Re: unset does not remove functions like a[b] unless -f is specified

2023-02-02 Thread Greg Wooledge
On Thu, Feb 02, 2023 at 03:02:41PM -0500, Dale R. Worley wrote: > Greg Wooledge writes: > > I'd be totally OK with restricting the function namespace a bit more. > > Function names should not be allowed to contain backticks or less-than > > or greater-than signs (

Re: unset does not remove functions like a[b] unless -f is specified

2023-02-02 Thread Greg Wooledge
On Fri, Feb 03, 2023 at 06:38:36AM +0700, Robert Elz wrote: > which is harmless, unless the shell is badly breaking the command > execution rules of POSIX (zsh does I believe) but because for any > shell that follows those rules, it is impossible to invoke a function > with a '/' in its name. unic

Re: Bash 5.2 breaks our Arch Linux devtools

2023-02-15 Thread Greg Wooledge
On Wed, Feb 15, 2023 at 05:35:10PM +0100, Mike Jonkmans wrote: > I once had that same issue: > https://lists.gnu.org/archive/html/bug-bash/2015-10/msg00013.html > > Conclusion: the shopt is not yet working until the function has been run. > (or after the line has been parsed). Yes. This is not a

Re: Vulnerability Report(No SPF Record)

2023-02-16 Thread Greg Wooledge
On Thu, Feb 16, 2023 at 07:21:14PM -, Syed Maaz wrote: > Hey Team, > > I am a security researcher,I have found this vulnerability related to > your website bash-hackers.org. Just for the record, "bash-hackers.org" is a third-party web site, not affiliated with the Free Software Found

Re: Cmd history is not displaying correctly

2023-02-19 Thread Greg Wooledge
On Sun, Feb 19, 2023 at 03:05:24PM +0200, Mr. Dick Steel wrote: > 4. Use up arrow to scroll cmd history up until you hit: > "$ valgrind --leak-check=full ./target/debug/hostname-ip-address" > and press up arrow once more and you will get: > "$ valgrind -cd rust/hostname-

Re: The memory occupied by bash has been increasing due to the fork bomb

2023-03-10 Thread Greg Wooledge
On Sat, Mar 11, 2023 at 10:50:21AM +0800, zju wrote: > So is it possible to optimize the continuous growth of memory occupied by > child processes? Someone will have to find where the memory leak is occurring. You'll want a more controlled reproducer than an infinite fork bomb. > Or is there an

Re: bash login shell detection broken using default compile options

2023-03-16 Thread Greg Wooledge
On Thu, Mar 16, 2023 at 05:21:23PM +0100, Tycho Kirchner wrote: > Hi, > when compiling bash with a plain > > mkdir build; cd build; ../configure && make > > the login shell detection (leading dash: -bash) is apparently broken - at > least, ~/.bashrc is not sourced. What you're referring to is a

Re: [PATCH] Save more readline state when running compgen

2023-03-21 Thread Greg Wooledge
On Tue, Mar 21, 2023 at 04:52:03PM -0400, Grisha Levit wrote: > On Tue, Mar 21, 2023 at 4:11 PM Chet Ramey wrote: > > OK, which do you think would be the more common case? Wanting the options > > used to generate completions to persist or using it in this way? > > Usually people do `COMPREPLY=($(

Re: why difference between interactive+script doing same thing?

2023-03-27 Thread Greg Wooledge
On Mon, Mar 27, 2023 at 12:24:35PM -0700, L A Walsh wrote: > interactive: > > readarray out< <(ssh -n -T "$user@$host" 'printf "1\n2\n3\n4\n5\n"' 2>&1); > printf "%s" "${out[@]}" > In script: > > on_host athenae 'printf "1\n2\n3\n4\n5\n"' Using host athenae > 103: host athenae, up > Read 1 lines

Re: [sorry for dups] Re: why difference between interactive+script doing same thing?

2023-03-27 Thread Greg Wooledge
On Mon, Mar 27, 2023 at 01:05:33PM -0700, L A Walsh wrote: > filter_ssh() { >ign0='ssh: connect to host \w+ port 22: Connection refused' >ign1='(agent returned different signature type ssh-rsa)' >ign2='(ssh_exchange_identification: read: Connection reset by peer)' >ign3='(packet_wri

Re: [sorry for dups] Re: why difference between interactive+script doing same thing?

2023-03-27 Thread Greg Wooledge
On Mon, Mar 27, 2023 at 04:43:09PM -0700, L A Walsh wrote: > On 2023/03/27 13:28, Greg Wooledge wrote: > > You're calling filter_ssh with no arguments, but trying to use "$@" > > inside it to generate the ssh command. > Isn't "$@" still valid?

Re: IFS field splitting doesn't conform with POSIX

2023-03-30 Thread Greg Wooledge
On Thu, Mar 30, 2023 at 05:12:46AM -0600, Felipe Contreras wrote: > IFS=, > str='foo,bar,,roo,' > printf '"%s"\n' $str > > There is a discrepancy between how this is interpreted between bash > and zsh: in bash the last comma doesn't generate a field and is > ignored, ... which is corr

Re: IFS field splitting doesn't conform with POSIX

2023-03-30 Thread Greg Wooledge
On Thu, Mar 30, 2023 at 11:52:06AM -0600, Felipe Contreras wrote: > Not to mention the small detail that the Internal Field Separator is > not a *separator*, but a terminator (with certain exceptions). POSIX itself admits that the name is confusing. From sh(1posix): RATIONALE [...]

Re: IFS field splitting doesn't conform with POSIX

2023-04-01 Thread Greg Wooledge
On Sat, Apr 01, 2023 at 07:44:10PM -0400, Saint Michael wrote: > There is an additional problem with IFS and the command read > > Suppose I have variable $line with a string "a,b,c,d" > IFS=',' read -r x1 <<< $line [...] https://mywiki.wooledge.org/BashPitfalls#pf47

Re: Possible problem with ${var%%[...]*}

2023-04-02 Thread Greg Wooledge
On Mon, Apr 03, 2023 at 12:28:25AM +0700, Robert Elz wrote: > bash is parsing the <() as a process substitution, producing nothing. > The only chars in the bracket expression will then be . and [ which > explains the result. That does seem like a bug, to be fair. > Try instead > > bash

Re: Junk at the end on history

2023-04-04 Thread Greg Wooledge
On Tue, Apr 04, 2023 at 08:34:02PM +0800, Dan Jacobson wrote: >There probably was. >Say, there should be a way to protect the user against something like >that. I wish I could just tell it to only allow utf-8 in my history. Can you please look in the history file, and confirm whether

Re: 'mapfile -O1 array' breaks '[[ -v array ]]'

2023-04-17 Thread Greg Wooledge
On Mon, Apr 17, 2023 at 10:23:17AM -0700, Wiley Young wrote: > Description: > When an array 'a_foo' is created with 'mapfile -d '' -t', it is > tested with '[[ -v a_foo ]]' and '[[' returns 0. When '-O 1' is added to > mapfile, '[[ -v a_foo ]]' returns non-0. It's not specifically the -O1

Re: Unnecessary bash warning message

2023-05-08 Thread Greg Wooledge
On Mon, May 08, 2023 at 08:28:36AM +0200, alex xmb ratchev wrote: > On Mon, May 8, 2023, 04:07 Hyunho Cho wrote: > > bash$ julia <( cat <<\@ ) 11 22 33 > > for a in ARGS println(a) end > > @ > > bash: warning: command substitution: 1 unterminated here-document > > 11 > > 22 > > 33 > > > > i d gue

Re: `wait -n` returns 127 when it shouldn't

2023-05-18 Thread Greg Wooledge
unicorn:~$ tty /dev/pts/0 unicorn:~$ ps -ft pts/2 UID PIDPPID C STIME TTY TIME CMD greg 973 959 0 Apr29 pts/200:00:00 bash greg 942813 973 0 07:29 pts/200:00:00 sleep 5 greg 942814 973 0 07:29 pts/200:00:00 sleep 7 unicorn:~$ ps

Re: nofork command substitution

2023-05-19 Thread Greg Wooledge
On Fri, May 19, 2023 at 01:36:44PM +0200, alex xmb ratchev wrote: > 'C ..' > ' ..' > '| ..' > > .. i dont get it Yeah, the wording isn't ideal. I'd start it out like this: ${ COMMAND; } ${| COMMAND; } Execute COMMAND in the current execution environment The first form (where the c

Re: nofork command substitution

2023-05-19 Thread Greg Wooledge
On Fri, May 19, 2023 at 02:25:15PM +0200, alex xmb ratchev wrote: > On Fri, May 19, 2023, 13:54 Greg Wooledge wrote: > > > On Fri, May 19, 2023 at 01:36:44PM +0200, alex xmb ratchev wrote: > > > 'C ..' > > > ' ..' > > > '| ..

Re: nofork command substitution

2023-05-19 Thread Greg Wooledge
On Fri, May 19, 2023 at 06:35:50PM +0200, alex xmb ratchev wrote: > so that i understand , > > var=${ awk ... } There's no reason to use this new thing if you're calling awk, because awk is an external program. You might as well just use var=$( awk ... ) instead. Either way, you're going to for

Re: setarray[unsetkey] doesn't trigger nounset in arithmetic context

2023-05-21 Thread Greg Wooledge
On Mon, May 22, 2023 at 07:01:18AM +1000, Martin D Kealey wrote: > [...] and treating "unset" as a fatal error is not the experience that > programmers have using other scripting languages, and is therefore, I would > argue, not something that should be added to the Shell, and certainly not > as a

Re: set -e not working as expected with conditional operators

2023-06-02 Thread Greg Wooledge
On Fri, Jun 02, 2023 at 09:01:11AM -0400, Chet Ramey wrote: > On 6/1/23 9:01 PM, rpaufin1 wrote: > > Consider the following script: > > > > #!/bin/bash > > > > f() { > > ls missing-file 2> /dev/null > > echo "test" > > } > > > > # 1 > > (set -e; f); ret=$? > > if (( ret )); the

Re: `verb=(--) declare -ax verb` causes an ENOTSOCK segfault

2023-06-16 Thread Greg Wooledge
On Fri, Jun 16, 2023 at 10:59:24AM -0400, Lawrence Velázquez wrote: > % /bin/bash -c 'foo= declare -ax foo' > zsh: segmentation fault /bin/bash -c 'foo= declare -ax foo' > > I am seeing this behavior with bash 3.2.57, so it appears to be > longstanding. I get a segfault/core dump in every versio

Re: Fwd: Crashing the Linux System

2023-06-17 Thread Greg Wooledge
On Sat, Jun 17, 2023 at 09:09:23AM +0530, LitHack wrote: > Running the yes command in command substitution will crash the linux shell. Not surprising, really. You're trying to capture and store an infinite number of bytes in memory. Eventually, either the malloc is going to fail due to lack of v

Re: Fwd: Command execution by creating file.

2023-06-20 Thread Greg Wooledge
On Wed, Jun 21, 2023 at 08:22:19AM +0530, LitHack wrote: > Special character '*' can be used to execute the command. "Doctor, it hurts when I bend my arm like this!"

Re: Fwd: Command execution by creating file.

2023-06-21 Thread Greg Wooledge
On Wed, Jun 21, 2023 at 09:25:02AM +0530, LitHack wrote: > Sorry instead of alias we have to use the function. > > Corrected command: mkdir dir;cd dir;<>file;file()bash;* Even if we correct your "corrected" code for you, the basic issue remains: what "bug" are you claiming exists here? How does

Re: Alias in command substitution

2023-06-21 Thread Greg Wooledge
eclare an alias, if issued in a subshell. I don't normally use it either, so let's try it and see: unicorn:~$ zsh greg@unicorn ~ % alias which-command=whence greg@unicorn ~ % (alias) which-command=whence greg@unicorn ~ % (alias x=date; alias) which-command=whence x=date The alias def

Re: It is possible that this can be a bug

2023-06-26 Thread Greg Wooledge
On Mon, Jun 26, 2023 at 03:36:58PM -0300, Hugo Napoli wrote: > #!/bin/bash > > clear > > echo "" > read -p "Ingrese un número entero de hasta 2 cifras > : " min > read -p "Ingrese otro número entero de hasta 2 cifras, mayor que el > anterior : " max > > if [[ ${#min} -gt 2 ]] || [[ ${#max}

Re: Funny behaviour of associative arrays

2023-06-27 Thread Greg Wooledge
On Tue, Jun 27, 2023 at 06:24:30AM -0500, Dennis Williamson wrote: > Your first assignment is a way to assign a list of members to an > associative array. Your second assignment creates a single element with the > index "[a]=b [c]=d" which has a null value. I'm seeing some parser voodoo here. uni

Re: maybe a bug in bash?

2023-06-29 Thread Greg Wooledge
uot; mydatabase EOF This is also described in a bit more detail at <https://mywiki.wooledge.org/BashProgramming/05#Passing_arguments_to_ssh>. I recommend reading that whole page when you get a chance. Here it is in action: unicorn:~$ password='$foo&bar' unicorn:~$ ssh localhost bash -s "${password@Q}" <<-'EOF' > printf 'Password is <%s>\n' "$1" > EOF greg@localhost's password: Password is <$foo&bar>

Re: maybe a bug in bash?

2023-06-30 Thread Greg Wooledge
On Fri, Jun 30, 2023 at 03:49:23PM +0200, Sebastian Luhnburg wrote: > You suggest to use an argument, to pass the password. Please correct me if I > be wrong, but to write one or more password(s) in clear text as an argument > in the terminal (./myscript.sh password1 password2) is not the best prac

Re: maybe a bug in bash?

2023-06-30 Thread Greg Wooledge
he password" > > EOF I wish you would remove the layers of obfuscation here, and just state clearly what you're doing. Why are you running /bin/bash inside the script which is already being executed by the remote user's shell? Is this is a stand-in for some other program

Re: maybe a bug in bash?

2023-06-30 Thread Greg Wooledge
On Sat, Jul 01, 2023 at 05:47:33AM +0900, Dominique Martinet wrote: > hm, this has the password show up in ps on the box executing ssh; > depending on the context that can be bad. Fair enough. We have no way to judge the OP's risk analysis, because they've kept almost everything secret so far. I

Re: maybe a bug in bash?

2023-07-01 Thread Greg Wooledge
On Sat, Jul 01, 2023 at 02:45:16PM +0200, alex xmb ratchev wrote: > declare -p > works well for transmitting bash vars around via ssh > > ssh foo "$(declare -p vars) > more code" I haven't tested that thoroughly, but it looks OK. However, it doesn't address the problem in this thread, which is t

Re: [BUG] Associative array initial reference name is made available in another context

2023-07-02 Thread Greg Wooledge
On Sun, Jul 02, 2023 at 03:04:25PM +0200, Top Dawn wrote: > > > > What makes you think so? Variables are always visible in invoked > > functions, unless you shadow them using local/declare/typeset. > > > > Thank you very much for this information, I didn't know invoked functions > inherited their

Re: Document m=1 m=2; echo $m result

2023-07-02 Thread Greg Wooledge
On Sun, Jul 02, 2023 at 08:56:08PM -0400, Lawrence Velázquez wrote: > On Sun, Jul 2, 2023, at 8:30 PM, Dan Jacobson wrote: > > OK, but do please mention somewhere that "if the variable is set more > > than once within the same statement, the final value is used." > > > > $ m=1 m=2; echo $m > > #(Y

Re: +=() can be used to set illegal indices

2023-07-04 Thread Greg Wooledge
On Tue, Jul 04, 2023 at 10:40:26AM +0200, alex xmb ratchev wrote: > On Tue, Jul 4, 2023, 01:52 Chet Ramey wrote: > > > On 7/3/23 5:56 PM, alex xmb ratchev wrote: > > > > > looked into non finite number libs ? > > > gawk like .. ? > > > > bignums? No. intmax_t is enough for the shell. > > > > yea

Re: slash appended to tab so its two // at end

2023-07-19 Thread Greg Wooledge
On Wed, Jul 19, 2023 at 09:06:20AM -0400, Chet Ramey wrote: > On 7/18/23 10:01 PM, alex xmb ratchev wrote: > > i in 5.2.15 bash aarch64 termux did > > > > $ cp -ap db2.*/ > > > > and got > > > > db2.i5// db2.i7// > > I can't reproduce this. It's probably an artifact of some Linux vendor's prog

Re: problem anomalies , possibly aliases related

2023-07-20 Thread Greg Wooledge
On Thu, Jul 20, 2023 at 11:03:35PM +1000, Martin D Kealey wrote: > On Thu, 20 Jul 2023, 18:03 Grisha Levit, wrote: > > > Sounds like you want all the commands in the alias to be executed as a > > group -- so you can just write it as one: > > > > alias bad='{ echo fail; continue; }' > > > > That

Re: problem anomalies , possibly aliases related

2023-07-20 Thread Greg Wooledge
On Fri, Jul 21, 2023 at 12:33:07AM +1000, Martin D Kealey wrote: > C has longjmp, and other languages have exceptions. Non-local break is a > usable "Bash shaped" analogue of those. Not perfect, sure, but close enough > to be useful. (Non-local continue is a logical extension of that.) > > Saying

Re: problem anomalies , possibly aliases related

2023-07-21 Thread Greg Wooledge
On Fri, Jul 21, 2023 at 01:15:16PM +0200, alex xmb ratchev wrote: > On Thu, Jul 20, 2023, 8:09 PM Greg Wooledge wrote: > > On Fri, Jul 21, 2023 at 12:33:07AM +1000, Martin D Kealey wrote: [...] > > Well in any case, the behavior you wanted is not reliable across shells, >

Re: suggestion: shell option for echo to not interpret any argument as an option

2023-07-26 Thread Greg Wooledge
On Wed, Jul 26, 2023 at 08:42:15AM -0400, Zachary Santer wrote: > To restate what's in the video, you can't safely use echo to print the > contents of a variable that could be arbitrary, because the variable could > consist entirely of '-n', '-e', or '-E', and '--' is not interpreted as the > end o

Re: BASH_SUBSHELL is not incrementing when part of a pipeline

2023-08-07 Thread Greg Wooledge
On Mon, Aug 07, 2023 at 01:56:21PM +, Kamil Cukrowski Priv wrote: > Hi, when BASH_SUBSHELL is part of a pipeline with just a simple command it > does not increment. Consider the following: > # docker run -ti --rm bash bash -c 'echo $BASHPID $BASH_SUBSHELL; echo | > echo $BASHPID $BASH_SUBSHELL'

Re: String replacement drops leading '-e' if replacing char is a space

2023-08-14 Thread Greg Wooledge
On Mon, Aug 14, 2023 at 06:40:28AM +0100, Kerin Millar wrote: > On Mon, 14 Aug 2023 02:11:27 + > pphick via Bug reports for the GNU Bourne Again SHell > wrote: > > > If a string starts with '-e' the replacement operators ${x//,/ } and ${x/, > > /} drop the '-e'. > > The behaviour seems to b

<    1   2   3   4   5   6   7   8   9   10   >