How to check the file existence using shell scripting in Solaris-10


 
Thread Tools Search this Thread
Operating Systems Solaris How to check the file existence using shell scripting in Solaris-10
# 1  
Old 11-24-2007
Error How to check the file existence using shell scripting in Solaris-10

Hi,

I have a script which will check the fiel existence, the lines are as below

if !(test -d ./data) then
mkdir data
fi


In the first line error occurs as below

generatelicense.sh: syntax error at line 2: `!' unexpected

Where as this script works fine in linux OS.

How to solve it?............................


Regards
Revathi
# 2  
Old 11-24-2007
Your code does not work with the Bourne shell (/bin/sh) which is the default shell on most UNIX systems. This is the case for Solaris.

To maximize shell script portability, you should try and write all your shell scripts so that they work with the Bourne shell.

The following works:

Code:
if [ ! -d ./data ]
then
    mkdir data
fi

As an aside it is good practice to use fully qualified pathnames i.e. /usr/bin/mkdir instead of just mkdir.
# 3  
Old 11-26-2007
MySQL

Quote:
Originally Posted by fpmurphy
Your code does not work with the Bourne shell (/bin/sh) which is the default shell on most UNIX systems. This is the case for Solaris.

To maximize shell script portability, you should try and write all your shell scripts so that they work with the Bourne shell.

The following works:

Code:
if [ ! -d ./data ]
then
    mkdir data
fi

As an aside it is good practice to use fully qualified pathnames i.e. /usr/bin/mkdir instead of just mkdir.

That's correct.
It works fine..............

Thanks
Revathi
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Check for existence of crash on Solaris 10

Hey all what is the command to check "Check for existence of crash/coredump files in /var/crash/"hostname" directory" thanks for help (4 Replies)
Discussion started by: gema.utama
4 Replies

2. Shell Programming and Scripting

File existence check

hi i wanted to check if the file exist or not(multiple files) DIRE=/home/V478 if ; then echo "file present" else echo "file not present" fi But i am getting the error as : [: unexpected operator/operand (3 Replies)
Discussion started by: ATWC
3 Replies

3. Shell Programming and Scripting

How to check line existence in shell ?

Hi, We have some config file and there we are looking to append a line if it is not found. abc.conf authpriv.* /var/log/secure mail.* -/var/log/maillog *.debug @vxhgt-hskhng02 cron.* ... (12 Replies)
Discussion started by: Litu19
12 Replies

4. UNIX for Dummies Questions & Answers

To check for existence of a file

I need to check for the existence of a file *.log in a specific directory using a perl script. Presently am not in that particular directory. So i am using chdir ("/path/to/my/file) And then i am using the -e in an if statement to check if it exists. if (-e $File) {......} $File contains the... (1 Reply)
Discussion started by: manutd
1 Replies

5. Shell Programming and Scripting

How to check for file existence?

i want to check if the file is in the directory or not, and also it should be handle error conditions, like missing files and report the error and exit. i did something like this: file ="hello" if !test -e "${file}" then echo "No such files exist!" exit 1 else do something....... fi ... (1 Reply)
Discussion started by: mingming88
1 Replies

6. Shell Programming and Scripting

shell :: check directory existence

Hi All, I have shell script and I need to check if some directory exist. I'm don't have the information if that directory is written in upper case or lowcase or mixed. Is there anyway to check the existence of that directory by ignoring case senestive? Thanks (3 Replies)
Discussion started by: Alalush
3 Replies

7. AIX

Check for File Existence

I have requirement where i need to search for files which start with SALESORDER and PURCHASEORDER. i need to process the files with SALESORDER first and then PURCHASEORDER. If SALESORDER files are not there i dont want to process PURCHASEORDER and i want to come out of script. I have written a code... (4 Replies)
Discussion started by: dsdev_123
4 Replies

8. AIX

check for file existence

Hello I am having a requirement like if there is no file in the directory then i need a message to pop on after the execution of the script. My script basically does for File in `ls -t $DIRECTORY | tail -1`; if there is no file the DIRECTORY then the script is simply exiting with out... (2 Replies)
Discussion started by: dsdev_123
2 Replies

9. AIX

how to check the existence of a file using korn shell?

we have tranferred an ear from local server to remote server using ftp.consider, we have an ear file named a.ear in remote server,again if we transfer the same file named a.ear from local server to remote server.we need the kshell to check the existence of the ear file in remote server,and if the... (3 Replies)
Discussion started by: karthikprasathk
3 Replies

10. AIX

how to check the existence of a file during ftp using korn shell?

i can able to transfer a file from build server(AIX)to webserver using ksh through ftp.my query is to check the existence of file while transfering from one server to other .i.e i need some command or script that checks the existence of file with same name in both server,within ftp syntax. ... (1 Reply)
Discussion started by: karthikprasathk
1 Replies
Login or Register to Ask a Question