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 Hack


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 Hack