Re: [here string] uncompatible change on here string function

2017-11-22 Thread Greg Wooledge
On Wed, Nov 22, 2017 at 11:22:47AM +0800, 尹剑虹 wrote: > The command line to the right of "<<<" is no longer cut by IFS > > [yjh@bash4.4 ~]$ var=$(echo -e "foo\t\tbar") > [yjh@bash4.4 ~]$ read a <<<$var; echo "$a" > foo bar > > [yjh@bash4.2 ~]$ var=$(echo

Re: [here string] uncompatible change on here string function

2017-11-22 Thread Greg Wooledge
On Wed, Nov 22, 2017 at 09:00:09PM +0700, Peter & Kelly Passchier wrote: > I think you are missing the point. He is claiming/reporting: Why write code that relies on the idiosyncratic behavior of a shell when it is given incorrect code? Whether bash handles incorrect code in one way or another se

Re: Re: [here string] uncompatible change on here string function

2017-11-27 Thread Greg Wooledge
On Fri, Nov 24, 2017 at 11:22:56AM +0800, 尹剑虹 wrote: > It's not the point. the problem is bash-4.4 auto add quote around $var or > $(cmd) after '<<<' > > On bash-4.2 and before following command always works fine > read ignore fstype <<<$(df --output=fstype $mountpoint) > > But after Update

Re: parenthesised regular expressions and non-greedy operator ? - non standard bash behaviour

2017-12-01 Thread Greg Wooledge
On Fri, Dec 01, 2017 at 06:40:35PM +0100, d...@computer42.org wrote: > I'm sanitising urls from advertisement crap. As described below I'm getting > a wrong resolution of parenthesised expression defined with non-greedy > operator '?'. > re='https?:\/\/toolbox.contentspread.net\/(.*?)=(.+?)&.*

Re: Missing documentation of the integer range (declare -i)

2017-12-06 Thread Greg Wooledge
On Wed, Dec 06, 2017 at 03:35:51PM +0100, H.-Dirk Schmitt wrote: > I carefully read the man page and find no definition of the defined > range of integer variables in bash. Bash uses signed 64-bit integers for arithmetic, since version 2.05b. Before that, it was either 32-bit or platform-defined;

Re: ~/.profile and ~/.bash_profile aren't executed on login

2017-12-11 Thread Greg Wooledge
On Mon, Dec 11, 2017 at 10:30:51AM -0800, Yuri wrote: > On 12/11/17 06:03, Chet Ramey wrote: > /usr/local/bin/bash is set as user's login shell in 'vipw'. So when this > user logs in, it must be invoked as a login shell. Is this correct? No. Because you are logging in with a Display Manager, not

Re: ~/.profile and ~/.bash_profile aren't executed on login

2017-12-11 Thread Greg Wooledge
On Mon, Dec 11, 2017 at 01:57:52PM -0500, Chet Ramey wrote: > On 12/11/17 1:30 PM, Yuri wrote: > > /usr/local/bin/bash is set as user's login shell in 'vipw'. So when this > > user logs in, it must be invoked as a login shell. Is this correct? > > Nobody on the list can answer that question. It de

Re: simple function causes BASH to exit when -e in effect

2017-12-22 Thread Greg Wooledge
On Fri, Dec 22, 2017 at 10:56:18AM -0800, Kevin Layer wrote: > The man page says: > > The shell does not exit if the command that fails is part of the > command list immediately following a while or until keyword, > part of the test following the if or elif reserved words,

Re: Bugreport builtin command 'read'

2018-01-04 Thread Greg Wooledge
On Thu, Jan 04, 2018 at 11:24:30AM +0100, sky...@top-email.net wrote: > # Bug 1?: +Option read -n1 > - Cursor doesn't jump automaticly to next line It's not supposed to. If you want that, just do an "echo" after the read. > # Bug 2: +Options read -n1 -e > - Command freezes in case of ty

Re: Bugreport builtin command 'read'

2018-01-04 Thread Greg Wooledge
On Thu, Jan 04, 2018 at 03:34:40PM +0100, sky...@top-email.net wrote: > Without the -n option, the read command is always terminated with a line break Untrue. Without -s, read simply echoes what the user types. That includes that newline (Enter) that normally terminates input (unless overridden

Re: declare/typeset can't set array to variable name

2018-01-05 Thread Greg Wooledge
On Fri, Jan 05, 2018 at 08:02:24AM -0500, Chet Ramey wrote: > On 1/4/18 9:27 PM, Tim Burnham wrote: > > tim@TimBookPro:~/ declare ${var2}="And this works" > > tim@TimBookPro:~/ declare ${var2}=( This breaks ) > > -bash: syntax error near unexpected token `(' > It's a syntax error. Pages that may

Re: set $'\001'; v=$* converted $'\001' to $'\001\001'

2018-01-15 Thread Greg Wooledge
On Mon, Jan 15, 2018 at 02:26:19PM +0800, Clark Wang wrote: > See following example: > > [STEP 100] # echo $BASH_VERSION > 4.4.12(4)-release > [STEP 101] # set -- $'\001' > [STEP 102] # v=$* > [STEP 103] # printf '%q\n' "$v" > $'\001\001' > [STEP 104] # Confirmed (with default IFS; it is importan

Re: time keyword evaluates following command's (builtin) argument

2018-01-16 Thread Greg Wooledge
On Tue, Jan 16, 2018 at 10:50:34AM +0200, Anti Räis wrote: > Description: > Bash unexpectedly evaluates a builtin command argument when it is > executed after `time` keyword. This does not happen when the builtin > command is executed at later time or with different type of argument. > ali

Re: [annoyance/non-feature] On OS X, every process is "occupying" CWD, making disk ejects impossible after cd'ing into them.

2018-01-16 Thread Greg Wooledge
On Tue, Jan 16, 2018 at 10:36:47PM +0800, Danyel Bayraktar wrote: > Initially I thought it was specific to the terminal emulator, but it is > actually due to the design of OS X. My problem is that when cd’ing into the > external drive to run an `ls`, I’m not really “using” it and should be able

Re: In a script, when you kill a process, you get a terminal style message...

2018-01-22 Thread Greg Wooledge
On Sun, Jan 21, 2018 at 10:23:52AM -0700, gaze...@xmission.com wrote: > 1) In a script, when you kill a process, you get a terminal style message > about the process being killed. See below for further description. Here's a simpler reproducer (no need for external symlinks or killall): wooledg:~

Re: Space as a key in an associative array - different behaviours

2018-01-25 Thread Greg Wooledge
On Thu, Jan 25, 2018 at 02:48:47PM +0100, Tomasz Warniełło wrote: > Repeat-By: > 1. > $ unset A; a=" ";declare -A A; ((A[$a]++)); declare -p A > declare -A A > > 2. > $ unset A; a=" ";declare -A A; let "A[$a]=1"; declare -p A > declare -A A > > 3. > $ unset A; a=" ";declare -A A; A[$a]=1; declare

Re: anomalous behaviour of ls command

2018-01-30 Thread Greg Wooledge
On Tue, Jan 30, 2018 at 01:54:36PM -0500, ken young wrote: > uname output: Linux Microknoppix 4.12.7-64 #13 SMP PREEMPT Tue Aug 15 > 04:56:38 CEST 2017 x86_64 GNU/Linux > Machine Type: i686-pc-linux-gnu > > Bash Version: 4.4 > Patch Level: 12 > Release Status: release > > I have a direct

Re: Feature request: PROMPT_COMMANDS array variable

2018-02-05 Thread Greg Wooledge
On Sat, Feb 03, 2018 at 02:57:33PM +0100, Egmont Koblinger wrote: > So the use case is: Someone wants to _add_ something to > PROMPT_COMMAND. How to do that? PROMPT_COMMAND+=$'\n''my new stuff' Or, test whether PROMPT_COMMAND is currently empty, and only append the newline (or semicolon) if it's

Re: make distclean breaks "later "configure && makes"", i.e., removes a file in distro that a build needs (cannot process parse.y)

2018-02-14 Thread Greg Wooledge
On Wed, Feb 14, 2018 at 01:03:05PM +0100, Michael Felt wrote: > If after a successful build, I run "make distclean" - "./configure && make"  > no longer works. > configure: WARNING: bison not available; needed to process parse.y > + /usr/bin/make > .buildaix/make.out > yacc: not found You need to

Re: Unset array doesn't work

2018-02-26 Thread Greg Wooledge
On Mon, Feb 26, 2018 at 09:57:10AM -0500, Clint Hepner wrote: > If necessary, you can define a global (at the expense of a single subprocess) > > myIFS=$(printf ' \t\n') That actually won't work, because $(...) strips the trailing newline(s). This might work: myIFS=$(printf ' \t\nx') myIFS=$

Re: Double substitution issue

2018-02-28 Thread Greg Wooledge
On Wed, Feb 28, 2018 at 03:25:21AM -0500, William Entriken wrote: > from=1 > to=3 > ls {$from..$to} > Bash fails the chained substitution with: > > ls: {1..3}: No such file or directory This is simply not a feature that bash implements. Bash does the expansions in the opposite order (brace expa

Re: Unset array doesn't work

2018-02-28 Thread Greg Wooledge
I think most people will agree that unset is extremely surprising, though they may point to different parts of it as the source of their surprise. 8 years after Freddy Vulto's initial investigations, there are many things I still don't understand. For example, consider this code straight from his

Re: Unset array doesn't work

2018-03-01 Thread Greg Wooledge
On Thu, Mar 01, 2018 at 10:34:30AM +0800, Clark Wang wrote: > Look at your answer to my question 6 years ago: > http://lists.gnu.org/archive/html/bug-bash/2012-04/msg00186.html I'm supposed to remember stuff from 6 years ago? Well crap, I'm in trouble then. Seriously, this behavior needs to be d

Re: Unset array doesn't work

2018-03-05 Thread Greg Wooledge
On Sat, Mar 03, 2018 at 08:24:06PM +0900, Koichi Murase wrote: > - Note: ksh seems not support local variables. "typeset" in function > scopes defines a global variable, and "unset" removes the global > variable. "Real ksh" has two different kinds of functions -- ones declared with "foo()" and one

Re: unexpected behavior with read

2018-03-05 Thread Greg Wooledge
On Sun, Mar 04, 2018 at 06:15:05PM -0500, Zach Hadgraft wrote: > Description: > global variable assignments fail when part of a sequence that > includes read and begins with a function invoked by command substitution > read can be invoked by another function, or invoked by another >

Re: coding standards

2018-03-06 Thread Greg Wooledge
On Tue, Mar 06, 2018 at 05:15:36PM +0800, Clark Wang wrote: > I don't know much about bash's source code so I cannot comment much. And > this kind of arguments are quite opinion based which are not simple yes/no > questions. That's precisely what a "coding standard" is -- an opinion. If one start

Re: indirect variable behavior breakage

2018-03-07 Thread Greg Wooledge
On Wed, Mar 07, 2018 at 10:54:22AM -0500, christopher barry wrote: > So yes 'ivar -3' is very, very bad indeed, and was a nasty bug, and I > absolutely agree that making sure the string is a validly formatted var > name before attempting to evaluate it is the right approach. > > My only request is

Re: [minor] umask 400 causes here-{doc,string} failure

2018-03-12 Thread Greg Wooledge
On Sun, Mar 11, 2018 at 03:17:42PM +, Stephane Chazelas wrote: > I can think of several ways to address it: > > 1- do nothing and blame the user as the user explicitly asked > for files to be unreadable This one gets my vote. That umask is just entirely wrong. Did the user really mean 0377

Re: Strange/incorrect behavior of a fake executable file

2018-03-14 Thread Greg Wooledge
On Tue, Mar 13, 2018 at 10:29:22PM -0600, Eduardo Bustamante wrote: > On Tue, Mar 13, 2018 at 7:24 PM, Vladimir Likic wrote: > > Repeat-By: > > > > $ echo junk > junk > > $ chmod +x junk > > $./junk > > --> this completely destroys my system Only if you have "." in your $PATH (or a function named

Re: which paradigms does bash support

2018-03-14 Thread Greg Wooledge
On Wed, Mar 14, 2018 at 10:47:09AM +0100, Marc Weber wrote: > I'm not a shell export, but I don't know how to return a list in bash. Same way you return a string, or a number, or anything else: you don't. Functions in bash aren't actually functions. They're user-definable commands (procedures).

Re: [Help-bash] which paradigms does bash support

2018-03-15 Thread Greg Wooledge
On Wed, Mar 14, 2018 at 02:11:32PM -0700, Andy Chu wrote: > Shell Has a Forth-like Quality > http://www.oilshell.org/blog/2017/01/13.html Similar to http://mywiki.wooledge.org/WrapperScript :) > Pipelines Support Vectorized, Point-Free, and Imperative Style > http://www.oilshell.org/blog/2017/01/

Re: Avoiding file-based constraints for tmp files (ws Re: [minor] umask 400 causes here-{doc,string} failure)

2018-03-15 Thread Greg Wooledge
On Wed, Mar 14, 2018 at 06:45:15PM -0700, L A Walsh wrote: > Is relying on HERE-doc implementation something that is portable? Is it > required by POSIX? Still a few things to remember... POSIX says "no": It is unspecified whether the file descriptor is opened as a regular file, a special f

Re: docs incorrectly mention pattern matching works like pathname expansion

2018-03-15 Thread Greg Wooledge
On Thu, Mar 15, 2018 at 06:50:24PM +, Stormy wrote: > if u think bash has builtin 'fnmatch' functionality, do u have an example? echo *

Re: docs incorrectly mention pattern matching works like pathname expansion

2018-03-16 Thread Greg Wooledge
On Fri, Mar 16, 2018 at 10:04:07AM +, Stormy wrote: > Thanks for the confirmation regarding the need to write code. and also about > 'cd' 'ls', yeah, it's what I sort of mean, bash does when passing args to > them, but there is no other way to 'access' this type of parsing.. You are still qu

Re: mapfile documentation

2018-03-16 Thread Greg Wooledge
On Fri, Mar 16, 2018 at 09:14:13AM -0400, Boruch Baum wrote: > In GNU bash, version 4.4.18(1)-release (x86_64-pc-linux-gnu), the first > line of the documentation for readarray / mapfile states: > >Read lines from the standard input ... > > However, it doesn't seem to accept input from a pipe

Re: mapfile documentation

2018-03-16 Thread Greg Wooledge
You forgot to Cc: the mailing list. I think this was on bug-bash...? On Fri, Mar 16, 2018 at 02:06:09PM -0400, Boruch Baum wrote: > On 2018-03-16 09:22, Greg Wooledge wrote: > > On Fri, Mar 16, 2018 at 09:14:13AM -0400, Boruch Baum wrote: > > > In GNU bash, version 4.4.18(1)-

Re: mapfile documentation

2018-03-16 Thread Greg Wooledge
On Fri, Mar 16, 2018 at 02:59:53PM -0400, Greg Wooledge wrote: > On Fri, Mar 16, 2018 at 02:06:09PM -0400, Boruch Baum wrote: > >echo $IFS |xxd > >: 0a > > This command will never reveal any information, period. I was slightly mistaken there. It actually

Re: mapfile documentation

2018-03-16 Thread Greg Wooledge
On Fri, Mar 16, 2018 at 03:45:42PM -0400, Boruch Baum wrote: > On 2018-03-16 14:59, Greg Wooledge wrote: > > wooledg:~$ set +m > > wooledg:~$ echo hello world | readarray; declare -p MAPFILE > > declare -a MAPFILE=([0]=$'hello world\n') > > > > lastpipe w

Re: ${parameter/pattern/string} behaviour changed

2018-03-16 Thread Greg Wooledge
On Fri, Mar 16, 2018 at 08:18:53PM +0100, d...@ftb-esv.de wrote: > Command: x="a b c"; echo "'${x// /','}'" > On old systems the output is: 'a','b','c' > In this version the output is: 'a,b,c' So, this LOOKS like an attempt to take a list, and write it out with single quotes aro

Re: question on retrieving map(-A) value w/indirect name

2018-03-19 Thread Greg Wooledge
On Fri, Mar 16, 2018 at 05:50:04PM -0700, L A Walsh wrote: > If I have assoc-array: > > declare -A foo=([one]=11 [two]=22) > > and am passing name in another var, like "fee" > > fee=foo > > I tried echoing the val: > > echo ${!fee[one]} > > but got nothing -- tried a few other syntaxes. 1

Re: bash long prompt, color going past the end of prompt after reaching bottom of terminal

2018-03-23 Thread Greg Wooledge
On Fri, Mar 23, 2018 at 12:36:22AM +0200, Ilkka Virta wrote: > I get the same with '4.4.12(1)-release' too, but it doesn't seem related to > Bash or the prompt. I can get it with just a printf, the colored part just > needs to get wrapped by the end of line. > > printf "%100s $(tput setab 1)color

Re: bash shows an error message about unpaired quotes, but they are paired

2018-03-27 Thread Greg Wooledge
On Mon, Mar 26, 2018 at 09:54:21PM +0200, f.de.kru...@gmail.com wrote: > #!/bin/bash > > run () { >echo "Running: ${*}" >eval ${*} If you're going to do it this way, that should be eval "$*" with the quotes. I strongly recommend NOT attempting this. If anything, this way would be sli

Re: important bug

2018-03-28 Thread Greg Wooledge
On Wed, Mar 28, 2018 at 08:22:16PM +0200, Klaus Bartels wrote: > If you execute the following script the result is wrong. It is self > explaining: > --- > # > # GNU bash, version 4.4.12(1)-release (x86_64-slackware-linux-gnu) > # Linux ... 4.9.31 #1 SMP Wed Jun 7 14:57:3

Re: Man Page: Confusing wording

2018-04-02 Thread Greg Wooledge
On Sat, Mar 31, 2018 at 05:00:51PM +0200, Lars Krueger wrote: >The line > >Of these list operators, && and || have equal precedence, followed >by ; and &, which have equal precedence. > >in the man page is rather confusing. I had to refresh my bison and >check parser.y to

Re: [BUG] ERR trap triggered twice when using 'command'

2018-04-02 Thread Greg Wooledge
On Mon, Apr 02, 2018 at 02:35:28PM +, Nick Chambers wrote: > On 4/1/18, 5:54 AM, "bug-bash on behalf of Martijn Dekker" > mart...@inlv.org> wrote: > > $ bash -c 'trap "echo WHOA" ERR; command false' > WHOA > WHOA > > Expected output: just one WHOA (as on *ksh, zsh) >

Re: Error message garbage when parameter expansion used inside (()) and variable unset

2018-04-03 Thread Greg Wooledge
On Mon, Apr 02, 2018 at 04:16:54PM -0500, PRussell wrote: > The above tells us what happens to an unset variable if not using parameter > expansion. > > But if a shell variable uses parameter expansion and is null or unset, what > does it evaluate to inside (()) syntax? The parameter expansion

Re: What should be the expected behavior for $_ ?

2018-04-03 Thread Greg Wooledge
On Tue, Apr 03, 2018 at 10:03:30AM -0400, Siteshwar Vashisht wrote: > $ mkdir testdir > $ cp rpmall.txt rpmshort.txt $_ # Use tab completion to complete filenames > cp: target '_filedir' is not a directory > > Last command fails because tab completing 'cp' command modifies value of > '$_'. Shall

Re: Error message garbage when parameter expansion used inside (()) and variable unset

2018-04-03 Thread Greg Wooledge
On Tue, Apr 03, 2018 at 12:15:14PM -0500, PRussell wrote: > ./t.sh: line 9: ���#V: var1 == : syntax error: operand expected (error > token is "== ") > > archlinux has the same version of bash and I got the same results as on > opensuse. I cannot reproduce this on Debian 9 amd64. Not with Debi

Re: $PS5, for sh -v!

2018-04-04 Thread Greg Wooledge
On Wed, Apr 04, 2018 at 11:25:26AM +0800, 積丹尼 Dan Jacobson wrote: > $PS4 is for sh -x. Well, $PS5 or $PSv should be for sh -v! > > Imagine, with just a simple PS5='$ ', one could produce > perfect dialogues, > > $ set -eu /tmp/x > $ mkdir $@ > $ cd $@ > $ seq 3|xargs touch > $ ls -U $@ > 3 2 1

Re: Process Substitution subshell inherits the desire to print its times if it contains explicit exit

2018-04-04 Thread Greg Wooledge
On Wed, Apr 04, 2018 at 11:21:56AM +0300, Basin Ilya wrote: > Hi. > > In an attempt to capture the output of 'time' https://mywiki.wooledge.org/BashFAQ/032

Re: Following symlinks in globstar (part 2)

2018-04-11 Thread Greg Wooledge
On Wed, Apr 11, 2018 at 10:21:03AM -0400, Chet Ramey wrote: > On 4/11/18 12:21 AM, Murukesh Mohanan wrote: > > This has come up in the past, and was somewhat resolved (< > > http://lists.gnu.org/archive/html/bug-bash/2014-03/msg00097.html>), but > > bash's behaviour is still a but surprising IMHO.

Re: Following symlinks in globstar (part 2)

2018-04-11 Thread Greg Wooledge
On Wed, Apr 11, 2018 at 06:16:19PM +0300, Ilkka Virta wrote: > So, given > > . > |-- dir > | +-- link -> ../otherdir > +-- otherdir > +-- subdir > +-- foo > > (that is: mkdir -p dir otherdir/subdir; ln -s ../otherdir dir/link; touch > otherdir/subdir/foo ) > > dir/**/foo does not

Re: [BUG] 'unset' fails silently under specific conditions

2018-05-02 Thread Greg Wooledge
On Wed, May 02, 2018 at 03:07:42PM +0100, Martijn Dekker wrote: > Let's see if I'm getting it right this time. In the following: > set -o posix > f() { foo=bar : ; } > f > the command 'foo=bar :' > 1. makes the assignment 'foo=bar' survive the ':' command; > 2. gives 'foo' a globa

Re: [BUG] 'unset' fails silently under specific conditions

2018-05-02 Thread Greg Wooledge
On Wed, May 02, 2018 at 10:32:52AM -0400, Greg Wooledge wrote: > wooledg:~$ bash > wooledg:~$ set -o posix > wooledg:~$ f() { foo=bar; foo=baz : ; }; f > wooledg:~$ declare -p foo > declare -x foo="baz" > > What did you see that led you to conclude there is a l

Re: Bash 4.3.48 does not wrap lines with TERM=screen

2018-05-09 Thread Greg Wooledge
On Wed, May 09, 2018 at 10:28:57AM +, Nikolay Nikolov wrote: > Hi, I have bash 4.3.48 and I use konsole as terminal emulator. The default > value is TERM=xterm. However, I want to use tmux and it requires that the > TERM value should be either screen or screen-256colors. The problem is that > a

Re: PDF documentation output not readable (3.2.6 GNU Parallel)

2018-05-10 Thread Greg Wooledge
On Thu, May 10, 2018 at 05:59:57PM +0200, Jorge Maldonado Ventura wrote: > There is an issue produced because a line is too long in PDF. See > attached image. parallel -k traceroute (the 'ute' is not readable in PDF > because the line is too long). I recommend splitting it in two separate > lines.

Re: PDF documentation output not readable (3.2.6 GNU Parallel)

2018-05-10 Thread Greg Wooledge
On Thu, May 10, 2018 at 09:12:01PM +, Eduardo Bustamante wrote: > El jue., may. 10, 2018 11:11 AM, Greg Wooledge > escribió: > > > [...] > > > from Section 3.2.6 GNU Parallel > > > > GNU parallel is a separate project from GNU bash. You'll want

Re: Variables can’t contain NUL

2018-05-21 Thread Greg Wooledge
On Sun, May 20, 2018 at 04:56:48AM +0200, Garreau, Alexandre wrote: > On 2015-11-13 at 07:17, Greg Wooledge wrote: > > Actually in the most general case, where those output streams may > > contain NUL bytes, it requires two temp files, because you can't store > > arbi

Re: Redirect to variable

2018-05-21 Thread Greg Wooledge
On Mon, May 21, 2018 at 10:12:43AM -0400, Chet Ramey wrote: > On 5/20/18 10:21 PM, PePa wrote: > > I would like to do something like this, where output gets redirected > > into a variable: > > > > some-command >>> variablename1 2>>>variablename2 > > > > command-with-many-output-descriptors >>> va

Re: Conditions with logical operators and nested groups execute "if" and "else"

2018-05-22 Thread Greg Wooledge
On Mon, May 21, 2018 at 04:17:18PM -0500, Uriel wrote: > [[ EXPRESSION ]]; && { TRUE CONDITION; } || { ALTERNATIVE RESULT; } https://mywiki.wooledge.org/BashPitfalls#pf22

Re: Conditions with logical operators and nested groups execute "if" and "else"

2018-05-31 Thread Greg Wooledge
On Wed, May 30, 2018 at 05:02:58PM -0700, L A Walsh wrote: > Greg Wooledge wrote: > > On Mon, May 21, 2018 at 04:17:18PM -0500, Uriel wrote: > > > [[ EXPRESSION ]]; && { TRUE CONDITION; } || { ALTERNATIVE RESULT; } > > https://mywiki.wooledge.org/BashPitfalls#pf22

Re: case pattern checking with bash -n fails

2018-06-01 Thread Greg Wooledge
On Fri, Jun 01, 2018 at 07:17:29PM +0200, Paul Förster wrote: > file: case-test (700) > ==8<-- > #!/bin/bash > > shopt -s extglob > case "${1}" in > +([[:alpha:]])*([[:alnum:]-_])) > echo "${1} matches" ;; > # ... some more cases here... > *) ech

Re: Bash don't interpret ~ path with multiple options.

2018-06-04 Thread Greg Wooledge
On Sun, Jun 03, 2018 at 02:32:03PM -0400, Chet Ramey wrote: > On 6/2/18 10:08 PM, Jungsub Shin wrote: > > # mount -o remount,append=~/test_aufs/ro1=ro+wh ~/test_aufs/mount > > > > mount failed with ~/test_aufs/ro1 path isn't exist message. > > So i try to debug with strace and i find out bash don'

Re: Sequence Brace Expansion Crash

2018-06-04 Thread Greg Wooledge
On Sat, Jun 02, 2018 at 09:18:14PM -0700, Thomas Fischer wrote: > Repeat-By: > echo {a..z}{a..z}{a..z}{a..z}{a..z}{a..z} 26^6 = 308915776 words of 6 bytes each, plus however much overhead is involved in constructing a list of 308915776 strings. You've probably gone well over 2 GB of virtual memor

Re: When reading less than wanted characters, "read" does not detect NUL bytes

2018-06-15 Thread Greg Wooledge
On Fri, Jun 15, 2018 at 03:03:21PM +0200, Davide Brini wrote: > $ printf 'a\x00\x00bc' | { while IFS= read -d '' -n 2 var; do echo "read: > $var, length: ${#var}"; done; } > read: a, length: 1 > read: , length: 0 > read: bc, length: 2 > > I would expect there to be another read of length 0 betwee

Re: $OPTIND varibale value is different from sh

2018-06-20 Thread Greg Wooledge
On Wed, Jun 20, 2018 at 05:16:48PM +0900, Hyunho Cho wrote: > set -- -a -bc hello world > > echo $OPTIND# sh, bash = 1 > > getopts abc opt "$@" > echo $opt, $OPTIND # sh, bash = a, 2 > > getopts abc opt "$@" # bash = b, 2 <-- > dif

Re: Redirect to variable

2018-07-03 Thread Greg Wooledge
On Tue, Jul 03, 2018 at 10:43:31PM +1000, Robert Durkacz wrote: > On 5/21/18 Chet Ramey wrote: > > > > What you're asking for is syntactic sugar for: > > > some-command > temp-file > > echo '#' >> temp-file > > variablename=$(< temp-file) > > rm -f temp-file > > variablename=${variablename%?} >

Re: Word boundary anchors \< and \> not parsed correctly on the right side of =~

2018-07-10 Thread Greg Wooledge
On Mon, Jul 09, 2018 at 10:46:13PM -0300, marcelpa...@gmail.com wrote: > Word boundary anchors \< and \> are not parsed correctly on the right side of > a =~ regex match expression. Bash uses ERE (Extended Regular Expressions) here. There is no \< or \> in an ERE. http://pubs.opengroup.org/onl

Re: Word boundary anchors \< and \> not parsed correctly on the right side of =~

2018-07-10 Thread Greg Wooledge
On Tue, Jul 10, 2018 at 10:02:34AM -0300, Paulo Marcel Coelho Aragão wrote: > It baffles me that literal \< \> are not evaluated correctly > > paulo:~$ [[ 'foo bar' =~ \ ]] && echo yes || echo no > no In this context, the backslashes serve only to "quote" the less-than and greater-than si

Re: Number with sign is read as octal despite a leading 10#

2018-07-10 Thread Greg Wooledge
On Tue, Jul 10, 2018 at 11:00:36AM -0400, Chet Ramey wrote: > On 7/9/18 9:24 PM, Isaac Marcos wrote: > > > Bash Version: 4.4 > > Patch Level: 12 > > Release Status: release > > > > Description: > > A value inside an arithmetic expansion is processed as octal despite using > > a 10# preffix. > >

Re: delcare -a on a nameref in a function modifies nameref instead of target

2018-07-18 Thread Greg Wooledge
On Tue, Jul 17, 2018 at 05:47:20PM -0400, Grisha Levit wrote: > At global scope this works as expected: > > $ declare -n ref=var; declare -a ref=(X); declare -p ref var > declare -n ref="var" > declare -a var=([0]="X") > > But in a function, we end up with the nameref variable having both the > `

Re: declare(1) not executing inside source'd script

2018-07-27 Thread Greg Wooledge
On Fri, Jul 27, 2018 at 12:26:06AM -0400, fr...@eec.com wrote: > produce any output (making me think that declare(1) > isn't being executed at all). For the record, declare is a builtin, not an external command with a man page in the (1) section, so writing "declare(1)" is extremely mi

Re: declare(1) not executing inside source'd script

2018-07-27 Thread Greg Wooledge
On Fri, Jul 27, 2018 at 12:26:06AM -0400, fr...@eec.com wrote: > Repeat-By: > $ cat <<__EOF__ >/tmp/bashbug.bash > > function myfunc { > > echo "Running..." > > } > > declare -fx myfunc > > declare -p -F | grep "myfunc" > > __EOF__ > $ source /tmp

Re: declare(1) not executing inside source'd script

2018-07-27 Thread Greg Wooledge
On Fri, Jul 27, 2018 at 10:44:49AM -0400, Frank wrote: > Agreed. But the bash installation does create a man page for it, does it > not? So a command like, “man 1 declare” does work...? I always thought this > was somewhat incongruous. Some Linux-based operating systems have a "builtins(1)" m

Re: Unquoted array slice ${a[@]:0} expands to just one word if IFS doesn't have a space

2018-08-01 Thread Greg Wooledge
On Wed, Aug 01, 2018 at 02:43:27PM +0300, Ilkka Virta wrote: > On both Bash 4.4.12(1)-release and 5.0.0(1)-alpha, a subarray slice like > ${a[@]:0} expands to just one word if unquoted (and if IFS doesn't > contain a space): This just reinforces the point that unquoted $@ or $* (or the array equiv

Re: Unquoted array slice ${a[@]:0} expands to just one word if IFS doesn't have a space

2018-08-01 Thread Greg Wooledge
On Wed, Aug 01, 2018 at 07:42:30PM +0700, pepa65 wrote: > On 08/01/2018 07:12 PM, Greg Wooledge wrote: > > This just reinforces the point that unquoted $@ or $* (or the array > > equivalent) is a bug in the script. It gives unpredictable results. > > If the results are unpr

Re: Unquoted array slice ${a[@]:0} expands to just one word if IFS doesn't have a space

2018-08-01 Thread Greg Wooledge
On Wed, Aug 01, 2018 at 04:06:03PM +0300, Ilkka Virta wrote: > Unquoted $* seems well-defined in Bash's reference manual: > > ($*) Expands to the positional parameters, starting from one. When the > expansion is not within double quotes, each positional parameter > expands to a separate word

Re: Unquoted array slice ${a[@]:0} expands to just one word if IFS doesn't have a space

2018-08-01 Thread Greg Wooledge
On Wed, Aug 01, 2018 at 09:05:20PM +0700, Robert Elz wrote: > Date:Wed, 1 Aug 2018 09:03:20 -0400 > From: Greg Wooledge > | What's the intent of a script that uses unquoted $@ or $*? > > Either (or both) of field splitting of the args, or filename e

Re: failglob handling

2018-08-03 Thread Greg Wooledge
On Fri, Aug 03, 2018 at 03:29:33PM +0200, Thomas Deutschmann wrote: > However, see the following interesting difference between semicolons and > newlines: > > > $ echo "shopt -s failglob; echo /foo/bar/*; echo alive; " | bash > > bash: line 1: no match: /foo/bar/* Yeah, my own testing confirms th

Re: Improper handling of \! and \( while using Bash V4.1.2

2018-08-06 Thread Greg Wooledge
On Mon, Aug 06, 2018 at 04:14:49PM +0530, anant garg wrote: > $ mode=! > $ [ "$mode" != "ro" -a "$mode" != "rw" ] && echo OK > + '[' '!' '!=' ro -a '!' '!=' rw ']' > bash: [: too many arguments The use of -a and -o as conjunctions inside a test or [ command is to be avoided. It's not POSIX compat

Re: Extglob *?(a)b matches every string

2018-08-13 Thread Greg Wooledge
On Sat, Aug 11, 2018 at 09:26:56PM -0700, Mark Polyakov wrote: >Bash Version: 4.3 >Patch Level: 46 >A A A An extglob pattern such as `*?(anything)something_else` will >match any string, even though it should only match strings that end >with something_else. This appears to be

Re: Unexpected delay in using arguments.

2018-08-13 Thread Greg Wooledge
On Sun, Aug 12, 2018 at 03:16:34AM -0400, Bize Ma wrote: > Which is a thousand times slower. > Bash 5 is even worse Pre-release bash sources use a debugging-friendly (slow) malloc. Or something. Damn, google is not helping me out here.

Re: Assignment of $* to a var removes spaces on unset IFS.

2018-08-14 Thread Greg Wooledge
On Mon, Aug 13, 2018 at 09:36:23PM -0400, Bize Ma wrote: > Note that 4.4.19 is newer than what is available in > https://www.gnu.org/software/bash/ The current patch level of bash can be obtained by downloading the most recent tarball from and then applying the subse

Re: Assignment of $* to a var removes spaces on unset IFS.

2018-08-15 Thread Greg Wooledge
This reply was sent to me without Cc-ing the list. I have added the Cc. On Tue, Aug 14, 2018 at 11:39:20PM -0400, Bize Ma wrote: > On Tue, 14 Aug 2018 12:34:31, Greg Wooledge said: > > > I will also repeat, once more, my advice that one should NEVER write > > a script cont

Re: Add sleep builtin

2018-08-22 Thread Greg Wooledge
On Tue, Aug 21, 2018 at 06:11:14PM -0700, L A Walsh wrote: > sleep .001 (ms sleep)...not practical if loaded each time) > I often use sleep .1/.3/.5 ... if the builtin doesn't support sleep times > < 1 second, then it's probably not worth it. > > Also, needs to actually sleep for the listed time.

Re: Nested extglob outputs "." ".."

2018-08-22 Thread Greg Wooledge
On Wed, Aug 22, 2018 at 09:57:19AM +0200, Michal Pesa wrote: > Hello, I have encountered a strange behavior of nested extended globs: > > $ echo * > .txt 000.txt 00.txt 0.txt a.txt b.txt c.txt > $ echo !(0.txt) > .txt 000.txt 00.txt a.txt b.txt c.txt > $ echo !(+(0).txt) > . .. a.txt b.txt

Re: Add sleep builtin

2018-08-22 Thread Greg Wooledge
On Wed, Aug 22, 2018 at 03:54:44PM +0300, Ilkka Virta wrote: > [...] and Bash already supports handling > subsecond times in at least 'read -t', so it's not that far fetched to > implement it in 'sleep' too. Ah, excellent point! OK, that plus the ksh compatibility definitely wins me over.

Re: Bash vi mode's e command (end of word) goes to eol when hitting a unicode character

2018-09-04 Thread Greg Wooledge
On Mon, Sep 03, 2018 at 01:13:03PM +0200, Enrico Maria De Angelis wrote: > The version number of bash: GNU bash, version 4.4.23(1)-release > The hardware and operating system: Arch LInux (constatly update) > The compiler used to compile: I didn't compile bash myself > A description of the bug behav

Re: bash 4.4.19

2018-09-19 Thread Greg Wooledge
On Wed, Sep 19, 2018 at 08:38:59AM +0300, Евгений Мёдов wrote: >for i in {1..5}; do >A A var${i}=$RANDOM >done What you want is an array. See . for i in 1 2 3 4 5; do var[i]=$RANDOM done echo "${var[1]}" declare -p var

Re: Special parameter ?

2018-09-21 Thread Greg Wooledge
On Fri, Sep 21, 2018 at 01:23:57PM +0200, esori...@gsyc.urjc.es wrote: > The man page of bash (Special Parameters section) says: > >? expands to the exit status of the most >recently executed foreground pipeline. > > Nevertheless, background commands also modify the > value of this varia

Re: bash sockets: printf \x0a does TCP fragmentation

2018-09-24 Thread Greg Wooledge
On Sat, Sep 22, 2018 at 11:50:17AM +0200, dirk+b...@testssl.sh wrote: > On 9/22/18 7:30 AM, Bob Proulx wrote: > > dirk+b...@testssl.sh wrote: > >> printf -- "$data" >&5 2>/dev/null > > > > What happens if $data contains % format strings? What happens if the > > format contains a sequence such as

Re: bash sockets: printf \x0a does TCP fragmentation

2018-09-25 Thread Greg Wooledge
On Tue, Sep 25, 2018 at 05:15:02AM -0700, L A Walsh wrote: > On 9/24/2018 6:05 AM, Greg Wooledge wrote: > > On Sat, Sep 22, 2018 at 11:50:17AM +0200, dirk+b...@testssl.sh wrote: > > > On 9/22/18 7:30 AM, Bob Proulx wrote: > > > > dirk+b...@testssl.sh wrote: > >

Re: bash sockets: printf \x0a does TCP fragmentation

2018-09-25 Thread Greg Wooledge
> On 9/25/18 9:04 AM, dirk+b...@testssl.sh wrote: > > env or exec: never thought about it (thanks!) but as both are external > > commands, that would mean upon every call one additional external program. > > (yes, I know that there is such thing as a fs buffer). Subshells also costs > > resources.

Re: comment on RFE: 'shift'' [N] ARRAYNAME

2018-09-27 Thread Greg Wooledge
On Tue, Sep 25, 2018 at 05:17:27PM -0700, L A Walsh wrote: > It struck me as it might be convenient if 'shift' could take an optional > arrayname as an argument. Would that be possible or would it cause some > incompatibility? The biggest issue here is how you specify the arguments. Shift alread

Re: comment on RFE: 'shift'' [N] ARRAYNAME

2018-09-27 Thread Greg Wooledge
On Thu, Sep 27, 2018 at 06:47:33PM +0300, Ilkka Virta wrote: > Can you make an array whose name even starts with a digit? No, that's also disallowed. Bash variable names (including arrays) must begin with a letter or underscore.

Re: exec

2018-09-28 Thread Greg Wooledge
On Fri, Sep 28, 2018 at 09:11:26AM +0300, Francis Gathea wrote: > Same thing in a shell script. > > On 28/09/2018, Francis Gathea wrote: > > Hi. Why is this function closing out my session if typed on the terminal? > > First, please do not "top-quote". When you resond, put your response UNDER t

Re: A possible bug on autocompletion after setting FUNCNEST level

2018-10-08 Thread Greg Wooledge
On Mon, Oct 08, 2018 at 02:06:39PM +0200, Valentin Bajrami wrote: > This is how I could reproduce this: > > f3d0r4:~/FOO# FUNCNEST=4 4 is ridiculously low. Set it higher.

Re: Command not found with builtins and variables

2018-10-10 Thread Greg Wooledge
On Wed, Oct 10, 2018 at 01:42:50PM +0200, b...@feusi.co wrote: > TEST=1 time ls time is not a builtin. It's a "keyword". It's a piece of the shell's syntax. It has special magical rules that apply to nothing else. If you want to set an environment variable in the temporary execution environmen

Re: GNU Bash v.4.4.23-5 built-in function 'set' produces variable outputs

2018-10-19 Thread Greg Wooledge
On Fri, Oct 19, 2018 at 09:41:41PM +0200, Ricky Tigg wrote: > Built-in function 'set' produces variable outputs. > $ export SSLKEYLOGFILE=/home/user/test > > $ set | grep SSL > SSLKEYLOGFILE=/home/user/test > _=SSLKEYLOGFILE This is not a bug. The Special Parameter "_" is explained in the manua

Re: GNU Bash v.4.4.23-5 built-in function 'set' produces variable outputs

2018-10-22 Thread Greg Wooledge
On Mon, Oct 22, 2018 at 12:54:42PM +0700, Robert Elz wrote: > Scripts that want to use $_ (if there are any, which I doubt) won't be > unsetting it and would continue to work, the rest of us (at least those of > us not insane enough to try and use it) could just "unset _" in .profile (etc) > and be

<    7   8   9   10   11   12   13   14   15   16   >