Skip to content

Need support for environment variables #440

Closed

Description

@kbumsik

was: "cd $HOME returns error: Expected string, got Primitive(Nothing)"

Hi, since cd ~ is not working yet #373 I'm trying to do same with cd $HOME but it returns the following error:

cd $HOME
error: Expected string, got Primitive(Nothing)

It looks like the shell does not recognize it as string, but echo $HOME works well:

echo $HOME
/home/kbumsik

Activity

  1. changed the title [-]cd $HOME returns error: Expected string, got Primitive(Nothing)[/-] [+]Need support for environment variables (was: "cd $HOME returns error: Expected string, got Primitive(Nothing)")[/+] on Aug 26, 2019
  2. changed the title [-]Need support for environment variables (was: "cd $HOME returns error: Expected string, got Primitive(Nothing)")[/-] [+]Need support for environment variables[/+] on Aug 26, 2019
  3. wycats commented on Aug 26, 2019

    @wycats
    Contributor

    At the moment there is no support for environment variables, but we definitely need them.

    Normal variables will have the syntax $<IDENT>, so we need something else for environment variables. The most straight-forward approach would be something like PowerShell's namespaced variables ($env:HOME). Do you have any other thoughts?

  4. kbumsik commented on Aug 26, 2019

    @kbumsik
    Author

    Oh I see, but then how echo $HOME still works?

    To me $env:HOME sounds better than conventional $HOME approach. I personally prefer $env.HOME though but $env:HOME is not a big deal to me. Here are some other considerations I can come up with:

    1. How export command would look like?
    2. How to per-command override? like HOME=/home/john any_command?
  5. wycats commented on Aug 26, 2019

    @wycats
    Contributor

    Oh I see, but then how echo $HOME still works?

    I think it probably works by accident:

    • echo is an external command
    • external commands get their arguments as strings -- eventually external commands will have interpolation for stuff like this, but right now they're just passed right through
    • it probably parses $HOME for you
  6. wycats commented on Aug 26, 2019

    @wycats
    Contributor

    How to per-command override? like HOME=/home/john any_command

    Yes, I think this syntax should "just work". I miss it dearly in PowerShell.

  7. added
    category:bug
    on Aug 26, 2019
  8. wycats commented on Aug 26, 2019

    @wycats
    Contributor

    I'm marking this as a bug since a shell without environment variable support isn't much of a shell.

  9. andrasio commented on Nov 3, 2019

    @andrasio
    Member

    @kbumsik For the moment since our latest release you could do

    env | get vars."HOME" | cd
    

    or echo $nu:env | get HOME

    The table that env gives is also in the var $nu:env

    Inspecting the environment you can do with the env command.

  10. andrasio commented on Nov 3, 2019

    @andrasio
    Member

    @kbumsik ~ was also fixed. Thank you!!! Please reopen or open a new issue if you see something not working as expected.

  11. robyoung commented on Jul 19, 2020

    @robyoung

    @andrasio your suggested sollutions don't seem to work for me.

    > nu --version
    nushell 0.16.0
    > env
    HOME=/home/robyoung
    PATH=/home/robyoung/.cargo/bin:/home/robyoung/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    > env | get vars."PATH"
    error: Type Error
      ┌─ shell:1:1
      │
    1 │ env | get vars."PATH"
      │ ^^^ Expected row or table, found string
    
    > echo $nu:env
    ───┬──
     0 │
    ───┴──
    >
    
  12. andrasio commented on Jul 19, 2020

    @andrasio
    Member

    @andrasio your suggested sollutions don't seem to work for me.

    > nu --version
    nushell 0.16.0
    > env
    HOME=/home/robyoung
    PATH=/home/robyoung/.cargo/bin:/home/robyoung/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    > env | get vars."PATH"
    error: Type Error
      ┌─ shell:1:1
      │
    1 │ env | get vars."PATH"
      │ ^^^ Expected row or table, found string
    
    > echo $nu:env
    ───┬──
     0 │
    ───┴──
    >
    

    Nu has changed a lot :)

    > echo $nu.path
    > echo $nu.config
    > echo $nu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions