# Net/ssh exec builtin command (cd)

**URL:** <https://www.ruby-forum.com/t/net-ssh-exec-builtin-command-cd/144182>\
**Category:** Ruby\
**Created:** [July 26, 2008, 8:45am UTC](https://www.ruby-forum.com/t/net-ssh-exec-builtin-command-cd/144182 "2008-07-26T08:45:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [July 26, 2008, 8:45am UTC](https://www.ruby-forum.com/t/net-ssh-exec-builtin-command-cd/144182/1 "2008-07-26T08:45:21Z")

</div>

when using ssh.exec!(“ls -al”) everything is ok however, if i try to use  
“cd /path/to” (a shell builtin command) i get back :  
exec: 4: cd: not found

on the device a “which cd” returns nothing.

is there a workaround ?

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [July 26, 2008, 10:07am UTC](https://www.ruby-forum.com/t/net-ssh-exec-builtin-command-cd/144182/2 "2008-07-26T10:07:13Z")

</div>

From: Une Bévue [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

# when using ssh.exec!(“ls -al”) everything is ok however, if i

# try to use

# “cd /path/to” (a shell builtin command) i get back :

# exec: 4: cd: not found

# on the device a “which cd” returns nothing.

# is there a workaround ?

show net/ssh version and code pls.

eg, i just run this,

Net::SSH.start( “10.2.10.1”, “botp:)”, :password=\>“secret=)”) do  
|session|  
puts session.exec! “cd /etc; ls -la”  
end

outputs=\>  
(irb):57: warning: parenthesize argument(s) for future version  
total 1220  
drwxr-xr-x 100 root root 8192 2008-06-25 19:40 .  
drwxr-xr-x 30 root root 4096 2008-06-25 18:50 …  
-rw-r–r-- 1 root root 2149 2006-04-07 16:16 adduser.conf  
-rw-r–r-- 1 root root 44 2008-06-25 19:37 adjtime  
-rw-r–r-- 1 root root 65 2006-04-28 18:52 aliases  
-rw-r–r-- 1 root root 12288 2008-05-05 15:29 aliases.db  
drwxr-xr-x 2 root root 8192 2008-06-25 18:53 alternatives  
…

works, right?

kind regards -botp

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [July 26, 2008, 10:45am UTC](https://www.ruby-forum.com/t/net-ssh-exec-builtin-command-cd/144182/3 "2008-07-26T10:45:49Z")

</div>

Peña, Botp [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> show net/ssh version and code pls.

net/ssh 2.0.3  
net/scp 1.0.1

— ssh\_exec\_ls.rb -----------------------------------------------------  
#! /usr/bin/env ruby

require ‘net/ssh’

result=“”  
options={  
:config =\> false,  
#:config =\> “/Users/yt/.ssh/ssh\_config”,  
:paranoid =\> false,  
#:verbose =\> :debug,  
:auth\_methods =\> [“publickey”],  
:user\_known\_hosts\_file =\> “/Users/yt/.ssh/known\_hosts”,  
:keys =\> [“/Users/yt/.ssh/id\_dsa”],  
:passphrase =\> “A very vety long passphrase.”,  
:port =\> 2222  
}  
Net::SSH.start(“169.254.0.2”, “root”, options) do |session|  
result=session.exec!(“cd /mnt/fat;ls -Al”)  
end

puts result  
— /ssh\_exec\_ls.rb ----------------------------------------------------

> eg, i just run this,
> 
> Net::SSH.start( “10.2.10.1”, “botp:)”, :password=\>“secret=)”) do |session|  
> puts session.exec! “cd /etc; ls -la”  
> end

about the same except authentification by passphrase.

> works, right?

i got :  
$ ./ssh\_exec\_ls.rb  
exec: 4: cd: not found

if, by command line, i log into the device :  
$ ./ssh\_connect.zsh open  
Enter passphrase for /Users/yt/.ssh/id\_dsa:  
Identity added: /Users/yt/.ssh/id\_dsa (/Users/yt/.ssh/id\_dsa)  
[…]  
Last login: Sat Jul 26 08:57:20 UTC 2008

# cd /mnt/fat

# ls -Al

-rwxr-xr-x 1 root root 6148 Jul 23 10:04 .DS\_Store  
[…]  
-rwxr-xr-x 1 root root 16384 Jul 19 07:52 x-loader.bin

# which cd

# 

notice “which cd” returns nothing, this is a builtin shell command.

for example on MacOS X :  
$ which cd  
cd: shell built-in command

i should mention the remote device is a handheld phone running linux  
Kernel 2.4.x (QTopia over OMAP 730 from TI)

also, I’ve a lot of “SCP did not finish successfully” not repeatable.  
those scp errors are only reported when using ruby (net/ssh + net/scp)  
but not when using my zsh script.
