Skip to content

cwd not support ~ #443

Closed
Closed

Description

@zgpio
ssh.execCommand('pwd', { cwd:  '~/server/bin' }).then(function(result) {
    console.log('STDOUT: ' + result.stdout)
    console.log('STDERR: ' + result.stderr)
})

result in cd '~/server/bin' ; pwd
then goto error: bash: line 0: cd: ~/server/bin: No such file or directory

Activity

  1. steelbrain commented on Sep 14, 2022

    @steelbrain
    Owner

    It's a limitation coming from the way things work, cannot help much in this regard without complicating things a lot.

    One alternative in this situation would be to spawn a shell, execute this command in there, and then print pwd. Try running (with exec) 'bash', ['-c', 'cd ~/server/bin', 'pwd'] and tell me if that works

  2. steelbrain commented on Nov 16, 2026

    @steelbrain
    Owner

    In v14, a cwd that starts with ~/ (or is just ~) is relative to the remote user's home directory: node-ssh leaves the ~ unquoted so the shell expands it, and still quotes the rest. Until then, use an absolute path, or $HOME with execCommand('cd ~/server/bin && pwd').

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions