What -f can do?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers What -f can do?
# 1  
Old 10-29-2014
What -f can do?

Just want to ask if -f can also use to check if a directory is existing. Below is my code



Code:
oap_find_patch_fnc()  {
echo "        Enter patch number you want to retract or 99 to exit \c"
read patch_number

	if [ $patch_number == 99 ] 
	then
		exit 0
	else
		if [ -f "directory_$patch_number" ]

# 2  
Old 10-29-2014
Hello cmarzan,

-f filename is true if a file exits and it is a regular file or not. You can refer man test also for same.

Following is an example for same.
Code:
if [ -f  Filename ]
then
       echo "file exits."
else
       echo "file is NOT there."
fi


Thanks,
R. Singh

Last edited by RavinderSingh13; 10-29-2014 at 11:27 AM.. Reason: corrected typo of a space in b/w filename and ] thanks to Aia for same.
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 10-29-2014
Hi,

To chck for a directory, you would want to use,
Code:
if [ -d  Dirname ]
then
       echo "directory exits."
else
       echo "directory is NOT there."
fi

Regards

Dave

Last edited by gull04; 10-29-2014 at 07:24 AM.. Reason: Typo
This User Gave Thanks to gull04 For This Post:
# 4  
Old 11-03-2014
Many thanks to you guys...
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question