LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Validating multiple file (https://www.linuxquestions.org/questions/linux-newbie-8/validating-multiple-file-4175415249/)

rameshpaul_cog 07-06-2012 09:59 AM

Validating multiple file
 
Hi,

It may be simple ... but am not getting a break here...Any help would be really appreciated...

I want to validate couple of variables before i execute a command

Here is the scenario

Code:

count=' ${NAME_SRC_PATH} | grep "^${name}\/$" | wc -l`
if [ $count -eq 0 ];
then
        echo "Error Creating ${name} "
        exit 1
else
        echo "Name Created."
fi

Now i want to check some 5 more src_path .. how can i chk that... ?

Say like NAME_SRC_PATH1,NAME_SRC_PATH2.NAME_SRC_PATH3,NAME_SRC_PATH4,NAME_SRC_PATH5...

the paths are declared by me only ...and if the name exists in NAME_SRC_PATH3 .. it should return name exits is 3...likewise..for all...

i understand its simple... am totally blank now... any pointer would be helpful....

crabboy 07-06-2012 10:41 AM

To check for blank variables, I usually do something simple like:

Code:

if [ x$VARIABLE == "x" ]; then
  echo blank
else
  echo not blank
fi

If you're looking to see if a directory exists then it's a bit different

Code:

if [ -d $DIRECTORY ]; then
  echo dir exists
fi


rameshpaul_cog 07-06-2012 10:50 AM

Hi...thanks first.....

no its not directory....

i think ...that if- conidtion will work.... thanks alot....

chrism01 07-08-2012 07:45 PM

See example 7.6 here http://tldp.org/LDP/abs/html/comparison-ops.html


All times are GMT -5. The time now is 05:51 PM.