3

I have simple script below,

if [ ! -e $c ];
then
mkdir "$c"
fi

$c is containing the folder path. I got the error mkdir: command not found. please help me out.

Thanks in advance. Navdeep

sabadow
  • 5,095
  • 3
  • 34
  • 51
Navdeep
  • 55
  • 1
  • 2
  • 6

1 Answers1

13

can you run mkdir in your login session?

If you can, most probably the problem is caused by PATH in your script, try suing full path:

if [ ! -e $c ];
then
/bin/mkdir -p "$c"
fi

or export PATH first

PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH
if [ ! -e $c ];
then
/bin/mkdir -p "$c"
fi
ray
  • 4,109
  • 1
  • 17
  • 12
  • Thanks alot, it worked. I have wasted my 3 hours on that only. thanks again. – Navdeep Dec 27 '13 at 13:00
  • I faced the same problem. Then i found that i've written `readonly PATH="$OPTARG"` in my script and the exported `PATH` variable in .bash_profile is being overwritten. so mkdir command is not found. Very bad, I should be more careful to set variable. – Md Shihab Uddin Jan 17 '19 at 07:26