Why might "mkdir -p" lead to a Bash permission error?

If I make a directory with mkdir -p, it causes problems with scripts

$ mkdir -p test2/test2

$ cd test2/test2

$ echo '#!/bin/sh
> echo hello' > hello.sh

$ ./hello.sh
bash: ./hello.sh: Permission denied


This is nothing to do with mkdir. You simply haven't given hello.sh executable permissions. You need the following:

chmod +x hello.sh

Check your permissions

Check the permissions on your directories and the script itself. There may be a problem there, although it's unlikely.

ls -lad test2/test2
ls -l test2/test2/hello.sh

You can always use the --mode flag with mkdir if your permissions aren't being set correctly for some reason. See chmod(1) and mkdir(1) for more information.

Execute the file directly

You can execute the script with Bash directly, rather than relying on a shebang line or the executable bit, as long as the file is readable by the current user. For example:

bash test2/test2/hello.sh
Change file permissions

If you can execute the file when invoked explicitly with Bash, then you just need to make sure your file has the execute bit set. For example:

chmod 755 test2/test2/hello.sh

Need Your Help

How do I create a Linux bootup USB stick that only runs my one program automatically?

linux usb boot

I want to create a USB stick that has the smallest version of Linux possible that only runs my one program automatically when booted from.

Pyro4 does not throw ConnectionClosedError

python-2.7 amazon-ec2 pyro

I'm running pyro 4.31. I need to be able to catch an exception when the proxy object loses connection to the remote object (i.e. when the server abruptly shuts down).