简体   繁体   中英

Mkdir error, Permission denied

Hi guys my code is as follows:

    #!/bin/bash

echo "What directory?"
read $dir

mkdir -p "$dir"/Air/Output
mkdir -p "$dir"/Oxy/Output

echo "done"

im getting the error "permission denied" Is it a problem

You should read dir , not read $dir .

With read $dir , your variable will not be set and with an empty dir variable, you attempt to create a directory from root /Air/Output which cause the permission denied.

As sjsam suggest, you may also add a prompt to read with its -p option :

read -p "What directory?" dir

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM