moved to bash instead of sh rewrite testing for existing file and directory so that hopefully it works on both Linux and MacOs