Find the answer to your Linux question:
Results 1 to 6 of 6
Hello This is probably a very easy thing to do, but I don't know how: I'd like to export an env't variable, and then use its reference in a Bash ...
  1. #1
    Linux Newbie
    Join Date
    Nov 2007
    Posts
    127

    Question [newbie] Dereferencing exported variable?

    Hello

    This is probably a very easy thing to do, but I don't know how: I'd like to export an env't variable, and then use its reference in a Bash script

    Code:
    # export MYDIR=/tmp
    
    # echo $MYDIR
    /tmp
    
    # find $(MYDIR)/user/lua/ -type f -name auxiliar.h
    MYDIR: command not found
    find: `/user/lua/': No such file or directory
    FWIW, the script is running on Ubuntu 10.04.

    Thank you for any help.

  2. #2
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    Use curly braces - {} - not parentheses - () ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  3. #3
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    drl is 100% correct.

    To be a bit more specific, ${foo} prints out the value of the foo variable. $(foo) runs the command "foo" and is replaced with its output.

    In your particular case, you can just say $MYDIR/usr/lua, because '/' cannot be part of a variable name, so Bash knows that the name of the variable is just MYDIR.
    DISTRO=Arch
    Registered Linux User #388732

  4. #4
    Linux Newbie
    Join Date
    Nov 2007
    Posts
    127
    Thanks for the tip. I saw this command in a Makefile and was wondering why it didn't work when I typed it at a Bash prompt.

  5. #5
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Ah, well, in Makefiles, $(var) is the command for a variable . Makefile scripting isn't the same as Bash scripting.
    DISTRO=Arch
    Registered Linux User #388732

  6. #6
    Linux Newbie
    Join Date
    Nov 2007
    Posts
    127
    Yup, that's what it looks like

Posting Permissions

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