Unnecessary bash warning message

2023-05-07 Thread Hyunho Cho
###

Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -flto=auto -ffat-lto-objects -flto=auto
-ffat-lto-objects -fstack-protector-strong -Wformat
-Werror=format-security -Wall
uname output: Linux EliteBook 6.2.0-20-generic #20-Ubuntu SMP
PREEMPT_DYNAMIC Thu Apr  6 07:48:48 UTC 2023 x86_64 x86_64 x86_64
GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.2
Patch Level: 15
Release Status: release

###


Process substitution can be used in place of a file in a command line
as follows:

bash$ cat test.jl
for a in ARGS println(a) end

bash$ julia test.jl 11 22 33
11
22
33

bash$ julia <( cat <<\@
for a in ARGS println(a) end
@
) 11 22 33
11
22
33

However, in the above method, the 11 22 33 arguments are placed at the
end of the command line,
which is not good for readability. So writing the following would make
the command line much more readable,
but it would output unnecessary warning messages.

bash$ julia <( cat <<\@ ) 11 22 33
for a in ARGS println(a) end
@
bash: warning: command substitution: 1 unterminated here-document
11
22
33



regex string ">(...)" in [[ ]] command recognize as process substitution

2022-10-30 Thread Hyunho Cho
##

Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -flto=auto -ffat-lto-objects -flto=auto
-ffat-lto-objects -fstack-protector-strong -Wformat
-Werror=format-security -Wall
uname output: Linux EliteBook 5.19.0-23-generic #24-Ubuntu SMP
PREEMPT_DYNAMIC Fri Oct 14 15:39:57 UTC 2022 x86_64 x86_64 x86_64
GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.2
Patch Level: 2
Release Status: release

##

I don't know if this is really a bug or not.
but the regex string ">(...)" in [[ ]] command is recognized as
process substitution
when using "( )" parentheses.

#  this all works fine #

val="delete  unset"

bash$ regex='(.*) <[^>]*> (.*)'
bash$ [[ $val =~ $regex ]] && echo yes
yes

bash$ [[ $val =~ (.*)\ \<[^\>]*\>\ (.*) ]] && echo yes
yes

bash$ [[ $val =~ ((.*) <[^>]*> (.*)) ]] && echo yes
yes

  remove spaces in regex string  ##

bash$ regex='(.*)<[^>]*>(.*)'
bash$ [[ $val =~ $regex ]] && echo yes
yes

bash$ [[ $val =~ (.*)\<[^\>]*\>(.*) ]] && echo yes
yes

# this is an error
# [[ ]] command recognizes ">(.*)" as process substitution.
bash$ [[ $val =~ ((.*)<[^>]*>(.*)) ]] && echo yes  # Error !
bash$ .*: command not found
^C

# if i escape \> then the error goes away
bash$ [[ $val =~ ((.*)<[^>]*\>(.*)) ]] && echo yes # Ok
yes

  The Second problem  #

This only happens in the terminal.

# 1. intentionally makes an error by removing escape "\>" to ">"
bash$ [[ $val =~ (.*)\ \<[^\>]*>\ (.*) ]] && echo yes
bash: syntax error in conditional expression: unexpected token `>'

# 2. fixed the error with \> escape, but the error continues
bash$ [[ $val =~ (.*)\ \<[^\>]*\>\ (.*) ]] && echo yes
bash: syntax error near unexpected token `$val'

# 3. On the second try, the error goes away.
bash$ [[ $val =~ (.*)\ \<[^\>]*\>\ (.*) ]] && echo yes
yes

  The third problem  #

This also happens only in the terminal.
but very unexpectedly happens

# 1. command executed successfully
bash$ [[ $val =~ (.*)\ \<[^\>]*\>\ (.*) ]] && echo yes
yes

# 2. but the output of the ${BASH_REMATCH[1]} variable is incorrect.
bash$ echo ${BASH_REMATCH[1]}
${ # or something like "${BASH_RE"

bash$ echo ${BASH_REMATCH[1]}
${

# 3. if i try again, it outputs normally.
bash$ [[ $val =~ (.*)\ \<[^\>]*\>\ (.*) ]] && echo yes
yes

bash$ echo ${BASH_REMATCH[1]}
delete



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

2022-10-27 Thread Hyunho Cho
##

Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -flto=auto -ffat-lto-objects -flto=auto
-ffat-lto-objects -fstack-protector-strong -Wformat
-Werror=format-security -Wall
uname output: Linux EliteBook 5.19.0-23-generic #24-Ubuntu SMP
PREEMPT_DYNAMIC Fri Oct 14 15:39:57 UTC 2022 x86_64 x86_64 x86_64
GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.2
Patch Level: 2
Release Status: release

##

bash "extglob" almost unusable except with very tiny string.
there is no such problems in zsh "kshglob".



# this is just for testing purposes.
$ foo=$( gcc -v --help 2> /dev/null | sed -En 's/^\s*(-[^ ]+).*/\1/p' )

# this is a simple work that just removes trailing spaces.
( in bash )$ time res=${foo%%+( )}
real0m10.409s # 10 seconds !
user0m10.408s
sys 0m0.000s

( in zsh )$ setopt kshglob
( in zsh )$ res=${foo%%+( )}"
Done immediately.



( in bash )$ res=${foo//*( )$'\n'*( )/$'\n'}
No hope

( in zsh )$ res=${foo//*( )$'\n'*( )/$'\n'}
Done almost immediately.



Parameter expansion with extended pattern make system hang

2022-09-04 Thread Hyunho Cho
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -flto=auto -ffat-lto-objects -flto=auto
-ffat-lto-objects -fstack-protector-strong -Wformat
-Werror=format-security -Wall
uname output: Linux EliteBook 5.15.0-43-generic #46-Ubuntu SMP Tue Jul
12 10:30:17 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.1
Patch Level: 16
Release Status: release

##


 "gcc --help" is already a short string, but the system hangs.
( without using extended pattern, there is no such problem )

bash$ help=$( gcc --help )

bash$ echo "${help//+([$' \t\n'])/ }"


 It barely works for very short strings only. (so almost can not use)

bash$ help=$( gcc --help | sed -n '1, 10p' )

bash$ echo "${help//+([$' \t\n'])/ }"
Usage: gcc [options] file... Options: -pass-exit-codes Exit with highest
error code from a phase. --help Display this information. --target-help
Display target specific command line options.
--help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...].
Display specific types of command line options. (Use '-v --help' to
display command
line options of sub-processes). --version Display compiler version information.
-dumpspecs Display all of the built in spec strings.



bash command completion has a problem with sudo command

2022-08-21 Thread Hyunho Cho
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -flto=auto -ffat-lto-objects -flto=auto
-ffat-lto-objects -fstack-protector-strong -Wformat
-Werror=format-security -Wall
uname output: Linux EliteBook 5.15.0-43-generic #46-Ubuntu SMP Tue Jul
12 10:30:17 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.1
Patch Level: 16
Release Status: release

##

when command completion function start running there are three
variables automatically setting

bash$ hello foo ba[tab]
$1 (command):   hello
$2 (current):ba
$3 (previous):  foo

bash$ echo -n "$COMP_WORDBREAKS" | od -a
000  sp  ht  nl   "   '   @   >   <   =   ;   |   &   (   :

bash$ hello --opt foo:[tab]# ":" is a member of $COMP_WORDBREAKS
$1 (command):   hello
$2 (current):(empty) # default behavior
$3 (previous):  foo

bash$ sudo hello --opt foo:[tab] # using sudo command
$1 (command):   hello
$2 (current)::  <- not empty
$3 (previous):  foo

In cases where the $2 variable's value is a member of the
$COMP_WORDBREAKS variable
then the $2 value is empty by default and has to use the
${COMP_WORDS[COMP_CWORD]} variable for that value.
I think this is good for making the completion function simpler.
but if I use the sudo command in front of the hello command then the
$2 value is not empty.
this ends up can not use $2 variable and force to use
${COMP_WORDS[COMP_CWORD]} variable



read built-in command has a problem in shell function

2021-10-10 Thread Hyunho Cho
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -flto=auto -ffat-lto-objects
-fstack-protector-strong -Wformat -Werror=format-security -Wall
uname output: Linux EliteBook 5.11.0-25-generic #27-Ubuntu SMP Fri Jul
9 23:06:29 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.1
Patch Level: 4
Release Status: release

###


If i want to know whether there are input available from stdin
then i use "read -t 0" command like this

if read -t 0; then# first check input available
while read line; do ... done
...
fi

this command works well in *shell script file*
but in shell function does not work well

sh$ myfunc() { if read -t 0; then echo yes; fi ;}

sh$ myfunc <<\EOF# OK
111
EOF
yes

sh$ myfunc <<< 111   # OK
yes

sh$ echo 111 | myfunc# OK
yes

sh$ cat foo.c | myfunc# NOT WORK!

sh$ date | myfunc   # NOT WORK!


 if i change like this. then this time work well

sh$ date | { date > /dev/null; myfunc ;}
yes



bash command alias has a problem in using brace.

2021-08-27 Thread Hyunho Cho
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -flto=auto -ffat-lto-objects
-fstack-protector-strong -Wformat -Werror=format-security -Wall
uname output: Linux EliteBook 5.11.0-25-generic #27-Ubuntu SMP Fri Jul
9 23:06:29 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.1
Patch Level: 4
Release Status: release

###

If i enter a command line like below then '>' prompt appears for the
input of here document.

bash$ { cat <<\@ > foo ;} 2> /dev/null
> 111
> 222  # '>' prompt
> @


but if i use alias then '>' prompt does not appear and default bash
prompt appears

bash$ alias myalias='{ cat <<\@ > foo ;} 2> /dev/null'
bash$ myalias
bash$ 111
bash$ 222  # bash$ prompt
bash$ @


this only occurs in brace

bash$ alias myalias='( cat <<\@ > foo ) 2> /dev/null'
bash$ myalias
> 111
> 222   # '>' prompt
> @



Re: Arithmetic pow results incorrect in arithmetic expansion.

2021-01-08 Thread Hyunho Cho
I didn't know that all other shells work the same.
Thanks for the clarification.




2021년 1월 9일 (토) 오후 2:29, Lawrence Velázquez 님이 작성:

> > On Jan 8, 2021, at 11:19 PM, Hyunho Cho  wrote:
> >
> > Machine: x86_64
> > OS: linux-gnu
> > Compiler: gcc
> > Compilation CFLAGS: -g -O2
> > -fdebug-prefix-map=/build/bash-a6qmCk/bash-5.0=.
> > -fstack-protector-strong -Wformat -Werror=format-security -Wall
> > -Wno-parentheses -Wno-format-security
> > uname output: Linux EliteBook 5.4.0-42-generic #46-Ubuntu SMP Fri Jul
> > 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
> > Machine Type: x86_64-pc-linux-gnu
> >
> > Bash Version: 5.0
> > Patch Level: 17
> > Release Status: release
> >
> > 
> >
> > i have tested below in gnome calculator, Qalculate, gawk, perl
> > and all results in -4 but bash is 4
> >
> > $ awk 'BEGIN { print -2 ^ 2 }'
> > -4
> >
> > $ perl -E 'say -2 ** 2'
> > -4
> >
> > $ echo $(( -2 ** 2 )) # only bash results in 4
> > 4
>
> The bash results disagree with awk and perl (and, admittedly, common
> mathematical convention), but the man page clearly states that unary
> minus has higher precedence than exponentiation, so this behavior
> is intentional.
>
> The operators and their precedence, associativity, and values are
> the same as in the C language. The following list of operators is
> grouped into levels of equal-precedence operators. The levels are
> listed in order of decreasing precedence.
>
> id++ id--   variable post-increment and post-decrement
> - + unary minus and plus
> ++id --id   variable pre-increment and pre-decrement
> ! ~ logical and bitwise negation
> **  exponentiation
> [remaining operators follow]
>
> Additionally, this precedence is consistent with other shells.
>
> % bash --version | head -n 1
> GNU bash, version 5.0.17(1)-release (x86_64-apple-darwin18.7.0)
> % bash -c 'printf %s\\n "$((-2 ** 2))"'
> 4
>
> % ksh --version
>   version sh (AT&T Research) 93u+ 2012-08-01
> % ksh -c 'printf %s\\n "$((-2 ** 2))"'
> 4
>
> % zsh --version
> zsh 5.8 (x86_64-apple-darwin18.7.0)
> % zsh -fc 'printf %s\\n "$((-2 ** 2))"'
> 4
> % zsh -f -o C_PRECEDENCES -c 'printf %s\\n "$((-2 ** 2))"'
> 4
>
> The zshmisc(1) man page even goes out of its way to address this.
>
> Note the precedence of exponentiation in both cases is below that of
> unary operators, hence `-3**2' evaluates as `9', not `-9'. Use
> parentheses where necessary: `-(3**2)'. This is for compatibility
> with other shells.
>
> I don't know why things shook out this way, but it sure seems like
> the ship has sailed.
>
> vq
>


Arithmetic pow results incorrect in arithmetic expansion.

2021-01-08 Thread Hyunho Cho
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2
-fdebug-prefix-map=/build/bash-a6qmCk/bash-5.0=.
-fstack-protector-strong -Wformat -Werror=format-security -Wall
-Wno-parentheses -Wno-format-security
uname output: Linux EliteBook 5.4.0-42-generic #46-Ubuntu SMP Fri Jul
10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.0
Patch Level: 17
Release Status: release



i have tested below in gnome calculator, Qalculate, gawk, perl
and all results in -4 but bash is 4

$ awk 'BEGIN { print -2 ^ 2 }'
-4

$ perl -E 'say -2 ** 2'
-4

$ echo $(( -2 ** 2 )) # only bash results in 4
4


Problems with command substitution and command alias

2020-11-21 Thread Hyunho Cho
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2
-fdebug-prefix-map=/build/bash-a6qmCk/bash-5.0=.
-fstack-protector-strong -Wformat -Werror=format-security -Wall
-Wno-parentheses -Wno-format-security
uname output: Linux EliteBook 5.4.0-42-generic #46-Ubuntu SMP Fri Jul
10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.0
Patch Level: 17
Release Status: release

###

### 1.

if command does not exist then the command stop with "command not found"
error
but the command substitution executed completely

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

prompt$ cd $(mktemp -d -p /dev/shm) &&
( curl -L https://ftp.gnu.org/gnu/bash/bash-5.1-rc3.tar.gz | tar xvz &&
cd bash-5.1-rc3 && ./configure && make -j `nproc` && strip bash ) &&
mv bash-5.1-rc3/bash "$OLDPWD" && rm -rf "$PWD" && cd -
bash-5.0: prompt$: command not found

$ ls -l /dev/shm/
total 0
drwx-- 2 mug896 mug896 40 2020-11-21 23:22 tmp.WK0k0MWZ2n/

---

### 2.

alias-expand-line readline function affects not only command line but also
heredoc contents

if i set up a command alias like below.  it works well as expected.

$ alias foo='make -f- << "EOF" 2> /dev/null'

$ foo
foo := 100
$(info $(foo))
EOF

100 # result

but if i hit a key that is bound to alias-expand-line readline function
for add more command line options of make
then foo is expanded not only in command line but also in heredoc contents

$ make -f- << "EOF" 2> /dev/null
make -f- << "EOF" 2> /dev/null := 100
$(info $(make -f- << "EOF" 2> /dev/null))
EOF


problem with using ctrl-x ctrl-e ( open vi editor )

2020-10-18 Thread Hyunho Cho
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2
-fdebug-prefix-map=/build/bash-a6qmCk/bash-5.0=.
-fstack-protector-strong -Wformat -Werror=format-security -Wall
-Wno-parentheses -Wno-format-security
uname output: Linux EliteBook 5.4.0-42-generic #46-Ubuntu SMP Fri Jul
10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.0
Patch Level: 17
Release Status: release

#

bash$ cat <<\EOF  # without using ctrl-x ctrl-e there is no problem
occurred.
> 111
> 222
> EOF
111
222

---

bash$ cat <<\EOF
> 111
>  < in this line open vi editor with ctrl-x ctrl-e
and add another 222 line then :wq


bash$ cat <<\EOF
> 111
>
cat <<\EOF
111
222
EOF
111< successfully executed cat command with heredoc
222
>
>
>
> ^C   < but does not end ">" prompt until enter ctrl-c


Commands that work in bash-5.0 but not in bash-5.1-rc1

2020-10-16 Thread Hyunho Cho
< bash-5.0 >

bash$ echo hello | cat <(cat) > >(tr a-z A-Z)
HELLO

< bash-5.1-rc1 >

bash$ echo hello | cat <(cat) > >(tr a-z A-Z)
   <-- empty

---

< bash-5.0 >

bash$ cat <<\@ | gcc -fPIC -shared -Wl,--version-script=<(cat) -o
libfoo.so foo.c
LIBFOO_1.0 {
global:
libfoo_init; libfoo_doit; libfoo_done;

local:
*;
};
@

< bash-5.1-rc1 >

bash$ cat <<\@ | gcc -fPIC -shared -Wl,--version-script=<(cat) -o
libfoo.so foo.c
LIBFOO_1.0 {
global:
libfoo_init; libfoo_doit; libfoo_done;

local:
*;
};
@
/usr/bin/ld:/dev/fd/63:0: syntax error in VERSION script
   < Error occurred
collect2: error: ld returned 1 exit status



background process in command substitution

2020-10-07 Thread Hyunho Cho
There are cases that need not wait until background process finish

--

In this case, zsh and bash wait 3 seconds to finish the assignment operation.
because sleep command's STDOUT is the pipe of command substitution.

< zsh >

$ AA=$( sleep 3 & date )# wait 3 seconds to finish

< bash >

$ AA=$( sleep 3 & date )# same as zsh



In this case, sleep command's STDOUT is redirected to FD 3
so there is no needs to wait 3 seconds
zsh return immediately with the value of background process PID
but bash still waits 3 seconds to finish the assignment operation.

< zsh >

$ exec 3>&1
$ PID=$(
date > >( sleep 3 >&3 ) & echo $!
)


< bash >

$ exec 3>&1
$ PID=$(
date > >( sleep 3 >&3 ) & echo $!
)



Things that work in bash-5.0 but not work in bash-5.1-rc1

2020-10-07 Thread Hyunho Cho
< bash-5.0 >

$ read rows cols < <(stty size)

$ echo $rows $cols
19 95

< bash-5.1-rc1 >

$ read rows cols < <(stty size)
stty: 'standard input': Inappropriate ioctl for device

$ echo $rows $cols
   < empty

---

< bash-5.0 >

# emacs start with contents of ls command output
$ ls | emacs < /dev/tty --insert <(cat)

< bash-5.1-rc1 >

# emacs does not start with contents of ls command output
$ ls | emacs < /dev/tty --insert <(cat)

---

< bash-5.0 >

$ ( trap 'uname' CHLD; date )
Wed Oct  7 16:39:55 KST 2020
Linux

< bash-5.1-rc1 >

$ ( trap 'uname' CHLD; date )   # some strange warning messages appear
Wed Oct  7 16:40:05 KST 2020
Linux
bash: warning: run_pending_traps: recursive invocation while running
trap for signal 17



coproc does not work in subshell

2020-10-02 Thread Hyunho Cho
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2
-fdebug-prefix-map=/build/bash-a6qmCk/bash-5.0=.
-fstack-protector-strong -Wformat -Werror=format-security -Wall
-Wno-parentheses -Wno-format-security
uname output: Linux EliteBook 5.4.0-42-generic #46-Ubuntu SMP Fri Jul
10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.0
Patch Level: 17
Release Status: release



bash$ coproc  while read -r line; do eval expr "$line"; done
[1] 172053

bash$ echo "1 + 2" >& ${COPROC[1]}; read -r <& ${COPROC[0]}; echo
$REPLY  # OK
3

bash$ echo $( echo "1 + 3" >& ${COPROC[1]}; read -r <& ${COPROC[0]};
echo $REPLY )   # command substitution : OK
4

bash$ cat <( echo "1 + 4" >& ${COPROC[1]}; read -r <& ${COPROC[0]};
echo $REPLY )  # process substitution : OK
5

bash$ ( echo "1 + 5" >& ${COPROC[1]}; read -r <& ${COPROC[0]}; echo
$REPLY )  # ERROR : subshell does not work
bash: ${COPROC[1]}: Bad file descriptor
bash: ${COPROC[0]}: Bad file descriptor
3



multi-line command history does not work when new terminal opened

2020-08-15 Thread Hyunho Cho
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2
-fdebug-prefix-map=/build/bash-a6qmCk/bash-5.0=.
-fstack-protector-strong -Wformat -Werror=format-security -Wall
-Wno-parentheses -Wno-format-security
uname output: Linux EliteBook 5.4.0-42-generic #46-Ubuntu SMP Fri Jul
10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.0
Patch Level: 17
Release Status: release




I have enabled the shell options for multi-line command history like this

shopt -s lithist
shopt -s cmdhist

and it works well in current terminal

bash$ history
 8651  echo history test 1
 8652  echo history test 2
 8653  echo history test 3
 8654  cat << EOF
111
222  # multi-line command history works well
333
EOF

 8655  history

---

if i opened new terminal then the multi-line commands all changed to
single lines like this

bash$ history
 7819  echo history test 1
 7820  echo history test 2
 7821  echo history test 3
 7822  cat << EOF
 7823  111  # the multi-line
commands changed to single lines
 7824  222
 7825  333
 7826  EOF
 7827  history



heredoc seems to parse contents even with the quoted delimiter in shell prompt

2020-08-15 Thread Hyunho Cho
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2
-fdebug-prefix-map=/build/bash-a6qmCk/bash-5.0=.
-fstack-protector-strong -Wformat -Werror=format-security -Wall
-Wno-parentheses -Wno-format-security
uname output: Linux EliteBook 5.4.0-42-generic #46-Ubuntu SMP Fri Jul
10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.0
Patch Level: 17
Release Status: release




if i use "test.sh" file for running shell script like this, there are
no error messages appear


bash$ cat test.sh
#!/bin/bash

cat << "EOF"
this is a test comment
$(info $(foo ${bar)))
EOF


bash$ ./test.sh  # no error messages appear
this is a test comment
$(info $(foo ${bar)))

---

if i use the same script in shell prompt then strange error messages appear


bash$ cat << "EOF"
this is a test comment
$(info $(foo ${bar)))
EOF
bash: command substitution: line 798: unexpected EOF while looking for
matching `}'
bash: command substitution: line 799: syntax error: unexpected end of file
bash: command substitution: line 798: unexpected EOF while looking for
matching `}'
bash: command substitution: line 799: syntax error: unexpected end of file
this is a test comment
$(info $(foo ${bar)))



bash errexit shell option does not work in some cases.

2020-05-31 Thread Hyunho Cho

GNU bash, version 5.0.16(1)-release (x86_64-pc-linux-gnu)
 Operating System: Ubuntu 20.04 LTS
 Kernel: Linux 5.4.0-33-generic
 Architecture: x86-64


bash errexit shell option does not work in some cases.
after execution a command, exitcode is set to "1" but shell script does not 
exited.


#   WORK CASE   ###

#!/bin/bash -e   # errexit option

cat < not_exist.txt # not exist file

echo end 

##  result  ##

$ ./test.sh  # work as expected
./test.sh: line 3: not_exist.txt: No such file or directory


###   NOT WORK  CASES  ###

#!/bin/bash -e

{ cat ;} < not_exist.txt   

echo "exitcode : $?"
echo end 

##  result  ##

$ ./test.sh 
exitcode : 1   # exitcode is set to "1" 
./test.sh: line 3: not_exist.txt: No such file or directory
end   # but test.sh does not exited

--

#!/bin/bash -e   

while read -r line; do 
echo "$line"
done < not_exist.txt  

echo "exitcode : $?"
echo end.

##  result  ##

$ ./test.sh
./test.sh: line 5: not_exist.txt: No such file or directory
exitcode : 1# exitcode is set to "1"
end.# but does not exited

$OPTIND varibale value is different from sh

2018-06-20 Thread Hyunho Cho

if $OPTIND value start from 1 then i think "-b" $OPTIND should be "3" like sh
but bash print "2"

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  <-- different 
from "sh"
echo $opt, $OPTIND# sh  = b, 3

getopts abc opt "$@" # sh, bash = c, 3
echo $opt, $OPTIND



bash process substitution weird behavior

2015-12-08 Thread Hyunho Cho
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I../. -I.././include -I.././lib  -D_FORTIFY_SOURCE=2 -g 
-O2 -fstack-protector-strong -Wformat -Werror=format-security -Wall
uname output: Linux EliteBook 4.2.0-19-generic #23-Ubuntu SMP Wed Nov 11 
11:39:30 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 4.3
Patch Level: 42
Release Status: release

Description:


1.

BASH$ { echo 111; echo 222 ;} 2> >( echo -en "\e[01;31m" >&2; read line; echo 
"$line" >&2; echo -en "\e[0m" >&2 ) >&2 

111# result is one line and red-colored that is expected behavior.



2.

# If i remove ">&2" that is at the end of command
# result is two lines with white-colored that is also expected behavior. 

BASH$ { echo 111; echo 222 ;} 2> >( echo -en "\e[01;31m" >&2; read line; echo 
"$line" >&2; echo -en "\e[0m" >&2 )

111# white colored
222# white colored



3. 

# If i add external "date" command in the middle of two echo commands
# result is in red-colored after external date command output
# i think there must be no red-colored because { echo 111; date; echo 222 ;} 
only direct to stdout

BASH$ { echo 111; date; echo 222 ;} 2> >( echo -en "\e[01;31m" >&2; read line; 
echo "$line" >&2; echo -en "\e[0m" >&2 )

111   # white colored
Tue Dec  8 20:33:33 KST 2015   # red colored
222   # red colored