@@ -35,7 +35,7 @@ use crate::wordexp::{expand_word, expand_word_to_string, word_to_pattern};
3535use nix:: errno:: Errno ;
3636use nix:: libc;
3737use nix:: sys:: wait:: { WaitPidFlag , WaitStatus } ;
38- use nix:: unistd:: { getpgrp, getpid, getppid, setpgid, ForkResult , Pid } ;
38+ use nix:: unistd:: { getcwd , getpgrp, getpid, getppid, setpgid, ForkResult , Pid } ;
3939use std:: collections:: HashMap ;
4040use std:: ffi:: { CString , OsString } ;
4141use std:: fmt:: { Display , Formatter } ;
@@ -942,13 +942,22 @@ impl Shell {
942942 environment. set_global_if_unset ( "PS4" , "+ " ) ;
943943 environment. set_global_if_unset ( "OPTIND" , "1" ) ;
944944 let history = initialize_history_from_system ( & environment) ;
945+ let current_directory = match getcwd ( ) {
946+ Ok ( path) => path. into_os_string ( ) ,
947+ Err ( err) => {
948+ eprintln ! (
949+ "sh: failed to determine the current working directory ({})" ,
950+ err
951+ ) ;
952+ std:: process:: exit ( 1 ) ;
953+ }
954+ } ;
945955 Shell {
946956 environment,
947957 program_name,
948958 positional_parameters : args,
949959 shell_pid : getpid ( ) . as_raw ( ) ,
950- // TODO: handle error
951- current_directory : std:: env:: current_dir ( ) . unwrap ( ) . into_os_string ( ) ,
960+ current_directory,
952961 history,
953962 set_options,
954963 is_interactive,
0 commit comments