help-bash
[Top][All Lists]
Advanced

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

[Help-bash] here-doc / linebreaks / indirect expansion


From: kardan
Subject: [Help-bash] here-doc / linebreaks / indirect expansion
Date: Sat, 22 Jun 2013 16:45:34 +0200

Hi,

I am confused by the output of my bash. Hopefully somebody can
explain, what I am doing wrong. I am using debian jessie [1]. 

#!/bin/bash
FIXME=<<-'FIXME'
        FIXME call pattern() with pattern name instead of pattern value
        (1 not $1) - according to man BASH 'indirect expansion'
        ${!parameter} is expanded to $parameter:
        FIXME
echo $FIXME
man bash|grep "indirect  expansion" -B9 -A2 # bash 4.2
var=DISPLAY ; echo "$var=${!DISPLAY} === $var=${!$var}"
exit

There are three unexpected obscurities
1. The first line is empty instead of showing my text after the <<HERE
doc. What is the correct syntax? I know there are differences between sh

           [n]<< delimiter
                 here-doc-text ...
           delimiter

and bash
              <<[-]word
                      here-document
              delimiter

2. The first quoted parapgrah (see below) of the manual is replaced by
a warning by i don't know. I am using tmux 1.8-3 and this is printed in
a vertically divided pane.

3. My use of indirect substitution seems to be inappropriate.

> $ LANG=en_US.utf8 logs
> 
> <standard input>:2180: warning [p 21, 6.7i]: can't break line
>               name.
> 
>        If the first character of parameter is an exclamation
>        point  (!), a level of variable indirection is intro‐
>        duced.  Bash uses the value of  the  variable  formed
>        from  the  rest of parameter as the name of the vari‐
>        able; this variable is then expanded and  that  value
>        is  used in the rest of the substitution, rather than
>        the value of parameter  itself.   This  is  known  as
>        indirect  expansion.   The exceptions to this are the
>        expansions of ${!prefix*} and  address@hidden  described
>        below.  The exclamation point must immediately follow
> 
> /usr/local/bin/logs: line 23: $var=${!DISPLAY} === $var=${!$va
> r}: bad substitution

This is how it should look like:

>         FIXME call pattern() with pattern name instead of pattern
> value (1 not $1) - according to man BASH 'indirect expansion'
>         ${!parameter} is expanded to $parameter:
> 
>        ${parameter}
>               The value of parameter is substituted.  The braces are
>        required when parameter  is  a  positional  parameter with
>        more  than  one  digit, or when parameter is followed by a
>        character which is not to be interpreted as part of its name.
> 
>        If the first character of parameter is an exclamation point
> (!), a level of  variable  indirection  is  introduced. Bash uses the
>        value of the variable formed from the rest of parameter as the
>        name of the variable; this variable is then expanded and that
>        value is used in the rest of the substitution, rather than the
>        value  of  parameter  itself. This  is  known  as  indirect
>        expansion.  The exceptions to this are the expansions of
>        ${!prefix*} and address@hidden described below.  The exclamation
>        point must immediately follow the left brace in order to
>        introduce indirection.
> 
> DISPLAY=:0 === DISPLAY=:0

Thanks!
Kardan

1] http://packages.debian.org/jessie/bash

BTW: The archive search of this list says "[ (can't open the index) ]".
http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query=indirect+expansion&submit=Search!



reply via email to

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