Doesn't MY_ENV=abc printf "${MY_ENV}\n" suppose to print abc?

Ask a Question related to Debian, Design and Development.

  1. #1

    Default Doesn't MY_ENV=abc printf "${MY_ENV}\n" suppose to print abc?

    Package: bash
    Version: 2.05b-8.1

    According to my understanding of the manual page,

    $ MY_ENV=abc printf "${MY_ENV}\n"

    Should have print abc. But it does not:

    $ MY_ENV=abc printf "${MY_ENV}\n"

    $

    What am I missing?


    -- System Information:
    Debian Release: testing/unstable
    Architecture: i386
    Kernel: Linux rakefet 2.4.21-3.custom586.1 #1 Fri Aug 1 21:48:39 IDT 200
    Locale: LANG=C, LC_CTYPE=C

    Versions of packages bash depends on:
    ii base-files 3.0.8 Debian base system miscella
    ii libc6 2.3.1-16 GNU C Library: Shared libra
    ii libncurses5 5.3.20030510-2 Shared libraries for termin

    -- no debconf information

    --

    Shaul Karl, shaul @ actcom . net . il


    --
    To UNSUBSCRIBE, email to [email]debian-user-request@lists.debian.org[/email]
    with a subject of "unsubscribe". Trouble? Contact [email]listmaster@lists.debian.org[/email]
    Shaul Karl Guest

  2. Similar Questions and Discussions

    1. #39479 [NEW]: printf ("%4.0f", -0.5) gives answer -1, instead of zero
      From: hjblik at hjb-ict dot com Operating system: linux PHP version: 4.4.4 PHP Bug Type: Math related Bug description: ...
    2. How to make "Print page" and "Print Chapter" buttons
      Hi my name is Jaco and I am a multimedia designer who uses Macromedia Director and Flash to create multimedia presentations. I have a request from a...
    3. Grey when I "export", black when I "print to Distiller"
      When I export my B&W ad, designed in InDesign 2.0.2, all the solid black areas in the resulting PDF are actually greyish-black. But if I send the...
    4. Can't choose "page setup" or "print" - Mac OS 9x
      Hello I have a problem on multiple Macs when using Freehand 10. I have not found any answers on macromedia Support or on the web. Before...
    5. Need Code for "Print This Page" "Print This Table"
      I need the code for "Print This Page" and especially for "Print This Table." I want to put this as a "link" from my main page. As is, if I...
  3. #2

    Default Re: Doesn't MY_ENV=abc printf "${MY_ENV}\n" suppose to print abc?

    * Shaul Karl (shaul@actcom.net.il) wrote:
    > Package: bash
    > Version: 2.05b-8.1
    >
    > According to my understanding of the manual page,
    >
    > $ MY_ENV=abc printf "${MY_ENV}\n"
    >
    > Should have print abc. But it does not:
    >
    > $ MY_ENV=abc printf "${MY_ENV}\n"
    >
    > $
    >
    > What am I missing?
    an 'export' and a ';', like so:

    $ export MY_ENV=abc ; printf "${MY_ENV}\n"
    abc

    iain

    --
    wh33, y1p33 3tc.

    "If sharing a thing in no way diminishes it, it is not rightly owned if it is
    not shared." -St. Augustine


    --
    To UNSUBSCRIBE, email to [email]debian-user-request@lists.debian.org[/email]
    with a subject of "unsubscribe". Trouble? Contact [email]listmaster@lists.debian.org[/email]
    iain d broadfoot Guest

  4. #3

    Default Re: Doesn't MY_ENV=abc printf "${MY_ENV}\n" suppose to print abc?

    * Shaul Karl (shaul@actcom.net.il) wrote:
    > On Sat, Aug 02, 2003 at 10:22:19PM +0100, iain d broadfoot wrote:
    > > * Shaul Karl (shaul@actcom.net.il) wrote:
    > > > Package: bash
    > > > Version: 2.05b-8.1
    > > >
    > > > According to my understanding of the manual page,
    > > >
    > > > $ MY_ENV=abc printf "${MY_ENV}\n"
    > > >
    > > > Should have print abc. But it does not:
    > > >
    > > > $ MY_ENV=abc printf "${MY_ENV}\n"
    > > >
    > > > $
    > > >
    > > > What am I missing?
    > >
    > > an 'export' and a ';', like so:
    > >
    > > $ export MY_ENV=abc ; printf "${MY_ENV}\n"
    > > abc
    > >
    >
    >
    > Your proposal has some side effects which might be undesirable. More
    > specifically, with your proposal MY_ENV will be set until you
    > explicitly unset it or exit the shell. With what I tried to do, MY_ENV
    > will only be set for the following command. There will be no need to
    > explicitly unset it or exit the shell in order for it to disappear
    > afterwards. In addition, the construct I am trying to use is a well
    > known construct and the man page says it should work. Is it a bug?
    i can't see in the man page an example like the one you show, what
    section is it in?
    > Can you try on your machine the line that I have asked about and see
    > if that is working for you? What version of bash are you using?
    i get the same results as you.

    the other respondent explained the reason for the (apparent) problem, i
    think.

    iain

    --
    wh33, y1p33 3tc.

    "If sharing a thing in no way diminishes it, it is not rightly owned if it is
    not shared." -St. Augustine


    --
    To UNSUBSCRIBE, email to [email]debian-user-request@lists.debian.org[/email]
    with a subject of "unsubscribe". Trouble? Contact [email]listmaster@lists.debian.org[/email]
    iain d broadfoot Guest

  5. #4

    Default Re: Doesn't MY_ENV=abc printf "${MY_ENV}\n" suppose to print abc?

    On Sat, Aug 02, 2003 at 10:22:19PM +0100, iain d broadfoot wrote:
    > * Shaul Karl (shaul@actcom.net.il) wrote:
    > > Package: bash
    > > Version: 2.05b-8.1
    > >
    > > According to my understanding of the manual page,
    > >
    > > $ MY_ENV=abc printf "${MY_ENV}\n"
    > >
    > > Should have print abc. But it does not:
    > >
    > > $ MY_ENV=abc printf "${MY_ENV}\n"
    > >
    > > $
    > >
    > > What am I missing?
    >
    > an 'export' and a ';', like so:
    >
    > $ export MY_ENV=abc ; printf "${MY_ENV}\n"
    > abc
    >

    Your proposal has some side effects which might be undesirable. More
    specifically, with your proposal MY_ENV will be set until you
    explicitly unset it or exit the shell. With what I tried to do, MY_ENV
    will only be set for the following command. There will be no need to
    explicitly unset it or exit the shell in order for it to disappear
    afterwards. In addition, the construct I am trying to use is a well
    known construct and the man page says it should work. Is it a bug?

    Can you try on your machine the line that I have asked about and see
    if that is working for you? What version of bash are you using?
    --

    Shaul Karl, shaul @ actcom . net . il


    --
    To UNSUBSCRIBE, email to [email]debian-user-request@lists.debian.org[/email]
    with a subject of "unsubscribe". Trouble? Contact [email]listmaster@lists.debian.org[/email]
    Shaul Karl Guest

  6. #5

    Default Re: Doesn't MY_ENV=abc printf "${MY_ENV}\n" suppose to print abc?

    On Sat, Aug 02, 2003 at 11:55:03PM +0100, iain d broadfoot wrote:
    >
    > i can't see in the man page an example like the one you show, what
    > section is it in?
    >

    Quoting the ENVIRONMENT section:

    The environment for any simple command or function may be augmented
    temporarily by prefixing it with parameter assignments, as described
    above in PARAMETERS. These assignment statements affect only the envi-
    ronment seen by that command.
    --

    Shaul Karl, shaul @ actcom . net . il


    --
    To UNSUBSCRIBE, email to [email]debian-user-request@lists.debian.org[/email]
    with a subject of "unsubscribe". Trouble? Contact [email]listmaster@lists.debian.org[/email]
    Shaul Karl Guest

  7. #6

    Default Re: Doesn't MY_ENV=abc printf "${MY_ENV}\n" suppose to print abc?

    On Sat, August 02 at 12:08 PM EDT
    Dave Carrigan <dave@rudedog.org> wrote:
    >On Sat, Aug 02, 2003 at 08:49:36PM +0300, Shaul Karl wrote:
    >
    >> According to my understanding of the manual page,
    >>
    >> $ MY_ENV=abc printf "${MY_ENV}\n"
    >>
    >> Should have print abc. But it does not:
    >>
    >> $ MY_ENV=abc printf "${MY_ENV}\n"
    >>
    >> What am I missing?
    >
    >The "MY_ENV=abc printf" syntax sets the environment variable for the
    >printf subprocess. And, in fact, when printf runs, MY_ENV is truly set
    >to abc. However, the "${MY_ENV}\n" is expanded *before* printf is
    >executed, and since MY_ENV is not set in the existing shell, the
    >expansion results in an empty string. The printf command doesn't even
    >see MY_ENV in its arguments, all it sees is a single argument that
    >looks like ``\n''.
    Can you elaborate a little more on this? I am curious, too. After
    reading your email I tried this:
    slamson@callerio:~$ unset COMMAND
    slamson@callerio:~$ COMMAND="printf" $COMMAND "x${COMMAND}\n"
    bash: x\n: command not found
    slamson@callerio:~$ COMMAND="printf" && $COMMAND "x${COMMAND}\n"
    xprintf
    slamson@callerio:~$

    So it seems that the variable is not assigned even for the subprocess.
    Does the shell see programs to execute before it looks to do variable
    substitution? I know the first things it sees are pipes and redirects
    but I don't know more.

    I must admit I had never thought of just running a command
    after an assignment so it has never come up. "Bug hunting" is great, but
    if the OP needs a solution for something, what about this:
    slamson@callerio:~$ unset MY_ENV slamson@callerio:~$ (MY_ENV=abc &&
    printf "x${MY_ENV}\n") xabc
    slamson@callerio:~$ echo x$MY_ENV
    x
    slamson@callerio:~$

    The parens make a subshell which is the "new environment" I assume the
    the man page is talking about, right?

    Thank you,

    Shawn Lamson
    [email]shawn.lamson@verizon.net[/email]


    --
    To UNSUBSCRIBE, email to [email]debian-user-request@lists.debian.org[/email]
    with a subject of "unsubscribe". Trouble? Contact [email]listmaster@lists.debian.org[/email]
    Shawn Lamson Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139