Advertisement
Guest User

cd.c

a guest
Sep 2nd, 2015
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.37 KB | None | 0 0
  1. #include <err.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7.     char *shell;
  8.     if (argc != 2)
  9.         errx(1, "Usage: cd /some/path");
  10.     if (chdir(argv[1]) == -1)
  11.         err(1, "chdir");
  12.     shell = getenv("SHELL");
  13.     if (!shell || !*shell)
  14.         shell = "/bin/sh";
  15.     execl(shell, shell, NULL);
  16.     err(1, "exec");
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement