Problem with Vagrant ssh shell command return code ($?)

47 views
Skip to first unread message

Johan Mazel

unread,
Nov 7, 2020, 4:23:26 AM11/7/20
to Vagrant
Hello
I created a setup single box which a Debian Buster.
I am trying to execute a command in a box and get its return code printed to stdout.

I run "ls; echo $?; ls toto; echo $?" where toto is not present.
On the host, the ouput is:
*content of directory*
0
ls: cannot access 'toto': No such file or directory
2
I get the 2 value because toto is not present.

Then I do "vagrant ssh client -c 'ls; echo $?; ls toto; echo $?'" (toto is again not present), and I get the following output:
*content of directory*
0
ls: cannot access 'toto': No such file or directory
0

Why is the return code/status of the second ls 0?

Thank you for your time.
Best regards,
Johan Mazel

Jim McGinness

unread,
Nov 7, 2020, 7:28:25 PM11/7/20
to vagra...@googlegroups.com
Probably need to defer interpretation of $? - looks like it may be getting evaluated early.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/vagrant/issues
Discuss: https://discuss.hashicorp.com/c/vagrant/24
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/24b4eaa7-795d-4cbd-b30c-87fe1b9c7307n%40googlegroups.com.

Johan Mazel

unread,
Dec 1, 2020, 10:04:52 AM12/1/20
to Vagrant
Actually, the problem disappeared so I have no idea actually happened.
It was probably a mistake on my side.
Reply all
Reply to author
Forward
0 new messages