Re: declare -p doesn't show the global attribute

2015-04-27 Thread isabella parakiss
On 4/27/15, Chet Ramey chet.ra...@case.edu wrote:
 On 4/26/15 5:26 PM, isabella parakiss wrote:
 $ fn () { declare -g var=x; declare -p var; } ; fn
 declare -- var=x

 I think the correct output should be declare -g var=x
 Is this intended or is it a bug?

 There is no such thing as `the global attribute'.  The -g option simply
 causes declare to create variables at the global scope instead of in a
 function-local scope.  The output you see is no different than what
 would have been displayed had `var' been declared and given a value at
 the global scope outside the function.


Ok I understand, but would it be possible to add it?

My use case may not be the best possible example, but I am sourcing a
library to set various parts of my interactive shells.  In this library
there's a function that sets the color variables from the output of tput.
Trying to avoid to call tput when it's not needed, I decided to save them
to an external file and source it if it exists.  My problem is that if I
source that file from the function, I'm setting local variables.  This is
the part that sets those variables:
https://gist.githubusercontent.com/izabera/d8f0f63fa3dc168af7b9/raw/581753078d33acea3d28b005722edb42c717fa96/gistfile1.sh

It seems to me that if declare -p showed the -g, I could just set them as
global and readonly before I save them, and I wouldn't need to set them
after I source them, in line 6.

Instead of declare -p, one could use something like printf %s=%q but it's
kinda hard to save arrays that way...


It's not a big deal, I just think it would make more sense.


---
xoxo iza



'help typeset' doesn't show -n option

2015-04-27 Thread Valentin Bajrami
Hi,

While looking at indirect reference of variables, typeset seems to support
the -n option.  For example

var=value
typeset -n ref=var
echo ${!ref}=$ref

However when running  ''help typeset''  I don't see the -n option.

[0][val@laptop:~]$ help typeset
typeset: typeset [-aAfFgilrtux] [-p] name[=value] ...
Set variable values and attributes.

Obsolete.  See `help declare'.

I'm sure I could use ''declare'' because of the above mentioned reason, but
shouldn't typeset mention it's -n option?


Valentin


Re: 'help typeset' doesn't show -n option

2015-04-27 Thread Chet Ramey
On 4/27/15 10:32 AM, Valentin Bajrami wrote:

 I'm sure I could use ''declare'' because of the above mentioned reason, but
 shouldn't typeset mention it's -n option?

Yes, it should.  typeset and declare are equivalent.  Thanks for catching
this.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



PROMPT_COMMAND causing strange cursor behavior

2015-04-27 Thread Martin Sebor

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-redhat-linux-gnu' 
-DCONF_VENDOR='redhat' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' 
-DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib  -D_GNU_SOURCE 
-DRECYCLES_PIDS -DDEFAULT_PATH_VALUE='/usr/local/bin:/usr/bin'  -O2 -g 
-pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions 
-fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches 
 -m64 -mtune=generic
uname output: Linux beacon 3.18.7-200.fc21.x86_64 #1 SMP Wed Feb 11 
21:53:17 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

Machine Type: x86_64-redhat-linux-gnu

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

Description:
When the PROMPT_COMMAND variable is set to a command such a printf
it causes the cursor to jump to disappear or jump to the wrong
positions when typing text that spans more than physical terminal
line. The problem exists in at least Bash 4.2 and 4.3 (but likely
earlier versions as well).

Repeat-By:
1) Open a terminal window (either XTerm or GNOME Terminal) 80
   columns wide. (The exact width shouldn't matter.)
2) Either set the TERM variable to vt100 or xterm, or unset it.
   The setting doesn't eliminate the problem but tends to have
   a slightly different effect on how it manifests.
3) Set the PROMPT_COMMAND variable to a string such as
   printf '123: ' and unset PS1 (the second part isn't
   necessary to reproduce the problem).
4) Observe the shell prompt and the cursor after the trailing
   space: 123: 
5) If using GNOME Terminal, type as many characters as necessary
   for the cursor to advance to the last column of the terminal
   window. Then type one more character and observe the cursor
   disappear. (It doesn't seem to disappear in XTerm.)
6) In either terminal proceed to type more characters. The line
   will wrap around, continuing in column 1. Before the cursor
   advances to line up with the first typed character on the
   line above, observe it jump to column 1.
7) Continue typing more characters and observe the text overwrite
   the previously typed and displayed characters.
8) Enter ctrl+a to move the cursor to the beginning of the typed
   line and observe it jump into the middle of the prompt instead
   to the beginning of the typed text.