简体   繁体   中英

Home directory shell

I am writing below script do create the home directory for the specific users and need to give ownership too.

Is the below the specified variable called userid will valid after home directory creation? gettig error when i run this script but home directory getting created but not chown

#!/bin/bash
#################### How to Check folder already exits or not #####################################################
read -p "Enter user id: " userid
if [ -d /tmp/$userid ]; then
echo -e "\e[31mFOLDER ALREADY EXISTS\e[0m"
else
mkdir /tmp/$userid
chown -R $userid:root $userid
fi

You need to replace the second instance of $userid with the directory name. So replace:

chown -R $userid:root $userid

with:

chown -R $userid:root /tmp/$userid

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