Permalink
Please sign in to comment.
Browse files
Implement 'command -v'.
Share logic with 'type -t', which largely does the same thing. The other flags to 'command' aren't implemented yet. Fixes issue #50.
- Loading branch information...
Showing
with
93 additions
and 22 deletions.
- +57 −21 core/builtin.py
- +5 −1 core/cmd_exec.py
- +26 −0 spec/builtins2.test.sh
- +5 −0 test/spec.sh
| @@ -0,0 +1,26 @@ | ||
| #!/bin/bash | ||
| ### command -v | ||
| myfunc() { echo x; } | ||
| command -v echo | ||
| echo $? | ||
| command -v myfunc | ||
| echo $? | ||
| command -v nonexistent # doesn't print anything? | ||
| echo $? | ||
| command -v for | ||
| echo $? | ||
| # stdout-json: "echo\n0\nmyfunc\n0\n1\nfor\n0\n" | ||
| # OK dash stdout-json: "echo\n0\nmyfunc\n0\n127\nfor\n0\n" | ||
| ### command -v with multiple names | ||
| # bash chooses to swallow the error! We agree with zsh if ANY word lookup | ||
| # fails, then the whole thing fails. | ||
| # All four shells behave differently here! | ||
| myfunc() { echo x; } | ||
| command -v echo myfunc ZZZ for | ||
| echo status=$? | ||
| # stdout-json: "echo\nmyfunc\nfor\nstatus=1\n" | ||
| # BUG bash stdout-json: "echo\nmyfunc\nfor\nstatus=0\n" | ||
| # BUG dash stdout-json: "echo\nstatus=0\n" | ||
| # OK mksh stdout-json: "echo\nmyfunc\nstatus=1\n" |
0 comments on commit
6ea7878