Hi guys,
How would i check a file exists with certainprefix? i have a directory with some files:
ABC1
ABC2
ABC3
etc..
and want to do:
please note i am using the korn shell environment.As when i gone through some stuff on then net i came to know some of the options will work differently based on the working shell environment.tht's wy i am specially mentioning my envrionment.
Code:
if [file exists with prefix ABC*] then
do something
else
do something else
fi
Hi redoubtable,
the below code is working for only exact file names(i mean the -f option).could you please tell me the way for finding files with certain prefix.I know the find command.but i need another way by using simple if command and along with their options.
redoubtable@Tsunami ~ $ ./s.ksh
file exists.
redoubtable@Tsunami ~ $ cat s.ksh
#!/bin/ksh
if [ -f ABC* ]
then
echo file exists.
else
echo not
fi
redoubtable@Tsunami ~ $
The '*' provides the capability of matching not only exact file names but also every file name starting with ABC. Remember that you must not use " in ABC.
Hi Franklin52,
"prefix=echo ${file:0:3}" when i am placing this code in my korn shell environment it is throwing a warning by saying "The specified substitution is not valid for this command". i think it is specific to evironment.
Can you please tell me the how would i write the same syntax in a korn shell enviroment?