how to check if path is present?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to check if path is present?
# 1  
Old 11-02-2004
how to check if path is present?

following situation...

- bourne shell script
- sb. should entry a path and the script should look if the path exists, when not it should restart the Input

...
echo "path\c"
read Inp
if [$Inp = ?????] ; then
echo " path doesn't exist, try again... "
(how to go back to the Inp?????)
else
echo " path exists "
.....
fi
...

thx for any advice...
# 2  
Old 11-02-2004
is there a chance by 'pathchk'? for example...

echo "path\c"
read Inp>file
VALID=pathchk `cat file`
if [$VALID != 0] ; then
echo " path doesn't exist, try again... "
(how to go back to the Inp?????)
else
echo " path exists "
..........
fi
..

is there also sth. like for files? like checking if the file is present and then return a zero.....
# 3  
Old 11-02-2004
for example for files...

echo "path\c"
read Inp1>file1
VALID1=pathchk `cat file1`
if [$VALID1 != 0] ; then
echo " path doesn't exist, try again... "
(how to go back to the Inp1?????)
else
echo " path exists "
cd `cat file1` (will not work, because of the directory..how to solve?)
cd `cat users/abc/file1`(should work)
echo "searching which file? \c"
read Inp2
find . -name "`cat file2`" >file3
VALID2=`cat file3`
if [ -f $VALID2 ] ; then
echo "$VALID2 exists"
....
else
echo "not existing"
(how to go back to the Inp2?????)
fi
..
fi
..
# 4  
Old 11-02-2004
MySQL I've found the solution...

no help needed anymore...thx

The test command evaluates the expression expr and, if its value is True, returns a zero (true) exit status; otherwise, a nonzero (false) exit status is returned. test also returns a nonzero exit status if there are no arguments. The following primitives are used to construct expr: -r file True if file exists and is readable.
-w file True if file exists and is writable.
-x file True if file exists and is executable.
-f file True if file exists and is a regular file.
-d file True if file exists and is a directory.
-c file True if file exists and is a character special file.
-b file True if file exists and is a block special file.
-p file True if file exists and is a named pipe (fifo).
-u file True if file exists and its set-user-ID bit is set.
-g file True if file exists and its set-group-ID bit is set.
-k file True if file exists and its sticky bit is set.
-s file True if file exists and has a size greater than zero.
-h file True if file exists and is a symbolic link.
-t [fildes] True if the open file whose file descriptor number is fildes (1 by default) is associated with a terminal device.
-z s1 True if the length of string s1 is zero.
-n s1 True if the length of the string s1 is non-zero.
s1 = s2 True if strings s1 and s2 are identical.
s1 != s2 True if strings s1 and s2 are not identical.
s1 True if s1 is not the null string.
n1 -eq n2 True if the integers n1 and n2 are algebraically equal. Any of the comparisons -ne, -gt, -ge, -lt, and -le can be used in place of -eq.

These primaries can be combined with the following operators: ! Unary negation operator.
-a Binary AND operator.
-o Binary OR operator (-a has higher precedence than -o).
( expr ) Parentheses for grouping.


------

by the way, go back to the Input by while->break....

------

also have a look here...

http://www.washington.edu/computing/...g/125/ctl.html
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List all the files in the present path and Folders and subfolders files also

Hi, I need a script/command to list out all the files in current path and also the files in folder and subfolders. Ex: My files are like below $ ls -lrt total 8 -rw-r--r-- 1 abc users 419 May 25 10:27 abcd.xml drwxr-xr-x 3 abc users 4096 May 25 10:28 TEST $ Under TEST, there are... (2 Replies)
Discussion started by: divya bandipotu
2 Replies

2. UNIX for Dummies Questions & Answers

Present Working Directory (not the full path)

Hi, Is there a command that tells you right away the current working directory? I know the command "pwd", but that one gives the full path. if pwd gives me: /a/b/c/d/ggg/HERE I want something that will give me: HERE Thanks, Gaurab (13 Replies)
Discussion started by: gaurab
13 Replies

3. Shell Programming and Scripting

How to Check whether list file present in TXT file exist or not

Hi All, I have txt file which has list of files. I have to check whether these files exist or not. Thanks supriya (6 Replies)
Discussion started by: supriyabv
6 Replies

4. Shell Programming and Scripting

check whether 3 files are present

I'm trying to check whether 3 files are existing and send 3 files as attachements. If only two are there then send those two files as attachments. if ; then elif ; then I tired the above given syntax and then it is giving me an error line 11: ' I tried with -a instead of && and... (3 Replies)
Discussion started by: Celvin VK
3 Replies

5. Shell Programming and Scripting

How to check the variable is present in array or not ?

Hi , I am trying to check wether the variable is present in the array. please see the below code .when ever i do this its taking only the first value of the array . please advise. ###Code Snnipet ### #!/bin/ksh set -xv if ]; then echo " you have Specified the ORG ID - $1 " ... (1 Reply)
Discussion started by: padhu.47
1 Replies

6. Shell Programming and Scripting

check if specified path is in $PATH

echo $PATH | grep "\/usr\/ucb" is not working using sh-posix The problem is very simle. I want to check '/usr/ucb' is in the PATH environment variable. If i simply grep '/usr/ucb' i might got wrong result eg '/usr/ucb/bin'. After the path an end of line or colon character should be. In... (4 Replies)
Discussion started by: fpeter75
4 Replies

7. Shell Programming and Scripting

How to get path and check in if statement

Hi, I was wondering if it possible to get the path of a variable and compare that to something. Basically I want to write a script that checks if my $JAVA_HOME is correct and if not then it sets it. So far I have... if ] then export JAVA_HOME='/pathhere' echo JAVA_HOME='/pathhere' fi ... (6 Replies)
Discussion started by: eltinator
6 Replies

8. Shell Programming and Scripting

Check whether the pattern is present or not?

I want to determine whether a specific pattern is present within a line or not e.g. The whole line is in a varaible called VALUE VALUE="(ABC, DEF, NMF, ABC, CLF, PAR, FHG, AGQSAs, sada, sa, ABC)" i want to set a flag to 1 if i find the presence of ABC in the above variable. Please... (8 Replies)
Discussion started by: skyineyes
8 Replies

9. UNIX for Advanced & Expert Users

how to check the actual path instead of link path

Hi I have a path link /test/df/link1/actual/file1 here link1 is actually a softlink link1= a/b i need to print the ACTUAL FULL path instead of a linked path is there any direct command to print the actual path of any linked path eg showPhyscialPath /test/df/link1/actual/file1 and it... (4 Replies)
Discussion started by: reldb
4 Replies
Login or Register to Ask a Question