[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

printf does not return error on readonly assignment

From: Arnaud Gaillard
Subject: printf does not return error on readonly assignment
Date: Thu, 6 Jul 2017 00:41:15 -0400


Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: cygwin
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash.exe' -DCONF_HOSTTYPE='i686'
-DCONF_OSTYPE='cygwin' -DCONF_MACHTYPE='i686-pc-cygwin'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'
-I/usr/src/bash-4.4.12-3.i686/src/bash-4.4/lib  -DWORDEXP_OPTION -ggdb
-O2 -pipe -Wimplicit-function-declaration
-Wno-parentheses -Wno-format-security
uname output: CYGWIN_NT-6.1-WOW Arnaud-PC 2.8.1(0.312/5/3) 2017-07-03
14:06 i686 Cygwin
Machine Type: i686-pc-cygwin

Bash Version: 4.4
Patch Level: 12
Release Status: release


            According to the help page of the `printf` builtin, it
should not return success when an error has occurred during the

> Exit Status:
> Returns success unless an invalid option is given or a write or assignment
> error occurs.

Assigning a value to a `readonly` variable returns an error code:

> bash$ readonly a=2
> bash$ a=3
> -bash: a: readonly variable
> bash$ echo $?
> 1

However, assigning the value to a `readonly` variable via `printf -v`
returns success:

> bash$ readonly b=2
> bash$ printf -v b 3
> -bash: b: readonly variable
> bash$ echo $?
> 0

I don't know whether this is an error coming from `help` or a bug of *bash*,
but it seems more logical to me that this is an error coming from *bash*.
Indeed, trying to use `printf` to assign a value to `$1` for example,
does return a error:

> bash$ printf -v 1 2
> -bash: `1': not a valid identifier
> bash$ echo $?
> 2


> bash$ readonly var=1
> bash$ var=2
> -bash: var: readonly variable
> bash$ echo $?
> 1
> bash$ printf -v var 2
> -bash: var: readonly variable
> echo $?
> 0

Sincerely yours,


reply via email to

[Prev in Thread] Current Thread [Next in Thread]