Article 4QN67 Bash script to accept argument and check the exist of directory inside /home using for loop

Bash script to accept argument and check the exist of directory inside /home using for loop

by
techlifehackblog
from LinuxQuestions.org on (#4QN67)
Hi Friends,

I have created below script to accept the positional parameter and base on that determine the exist of directory.

#!/bin/bash
#This directory will check the exist of directory in home directory.
directory=/home/$*
function checkd {
if [[ -d $directory ]]
then
echo "$directory is a directory"
else
echo "$directory is not a directory"
fi
}
for file in $*
do
checkd $file
done;

When I am providing the one argument with script, it is working fine.

./homedir myvijay

/home/myvijay is a directory

The problem, I need to check the exist of multiple directory inside /home but when I am giving multiple argument, below error coming.
./homedir myvijay Nancy

/home/myvijay nancy is not a directory
/home/myvijay nancy is not a directory

The reason, I need this script to check the home directory for every while doing the backup.

I tried different method but no luck, please help.

Thanks and Regards,

TechLife Hacklatest?d=yIl2AUoC8zA latest?i=pr6PmxMfqCw:OTqjKhb0KXo:F7zBnMy latest?i=pr6PmxMfqCw:OTqjKhb0KXo:V_sGLiP latest?d=qj6IDK7rITs latest?i=pr6PmxMfqCw:OTqjKhb0KXo:gIN9vFwpr6PmxMfqCw
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments