07-04-2005
FYI ust:
if [ -d $dir ]
then
...
fi
is actually using the 'test' command. To find out what you can do with the test command then type: 'man test'
You may also write the above as:
if test -d $dir
then
...
fi
or even use the test command on the comand line thus:
>test -d $dir
>echo $?
Also I would recommend shell variables to be quoted in this context:
if [ -d "$dir" ] ...
to avoid any command line errors with the test command!
i.e. if $dir were emtpy and you did if [ -d $dir ], then you would really be running: 'test -d' and the test command would complain.
Hope this helps.
MBB
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
say i would like to check if the file is existed before i use rm command. How can i do it?
i know if i can use find, but i would like to have a good interface (in a shell script)
thks (3 Replies)
Discussion started by: gusla
3 Replies
2. Shell Programming and Scripting
Hi there,,
how to check if directory/file exist using c/c++ under unix/linux? I can use access() under Window MFC. Thanks.
Steven (1 Reply)
Discussion started by: steven88
1 Replies
3. Programming
Hi there,
how to check if directory/file exist using c/c++ under linux/unix. Thanks.
Steven (2 Replies)
Discussion started by: steven88
2 Replies
4. Shell Programming and Scripting
We recieve some logs on our windows box via FTP on a daily basis, in the same directory. I would like to check for missing logs files and add their name to a text file.
Something like...
Check if C:\logs\file1_currentdate exists (if not, add file1_currentdate to... (1 Reply)
Discussion started by: SunnyK
1 Replies
5. Shell Programming and Scripting
There are many servers and their directory structer should be exactly the same. To check the directory path for all servers, I wrote a script.
#! /bin/ksh
ARRAY_DIRECTORIES="/c/dev/custom/bin"
ARRAY_DIRECTORIES="/c/dev/db/custom/src"
ARRAY_ENV="remoteName200"
ARRAY_ENV="remoteName201"... (2 Replies)
Discussion started by: weonpc
2 Replies
6. Shell Programming and Scripting
Hi,
I want to write a shell script to check whether a directory (say A) is existing in a given location and if it is not, create it. (3 Replies)
Discussion started by: sabya
3 Replies
7. Shell Programming and Scripting
Hi
Does anybody know how I can check if a file exists
i.e. see bellow, this doesn't work by the way and if tried countless variations on this
file1=$one/file111.txt
if
then
echo "Present"
else
echo "Not present"
fi
result :
Not present
(file is already present, eventhough its... (3 Replies)
Discussion started by: gksenthilkumar
3 Replies
8. Shell Programming and Scripting
Hi,
I am trying to create a bash script which will check if file exist then remove that file else do nothing. I have to do same process for three files in same script. I have written code for one file and trying to run it.
if
then
rm -r /user1/abc/File1
fi
When I run this code it... (1 Reply)
Discussion started by: palak08
1 Replies
9. Shell Programming and Scripting
Hi,
I created following script to check if file exist:
#!/bin/bash
SrcDir=$1
SrcFileName=$2
SrcTimePeriod=$3
if ;then
echo 1
else
echo 0
fi
I ran it like: /apps/Scripts/FileExist.sh /apps/Inbox file1 2nd_period_2010
Even file exist at that location, my above command is... (4 Replies)
Discussion started by: palak08
4 Replies
10. Shell Programming and Scripting
HI folks,
can any one tell me how to check whether the file is existed in a directory or not .
let me tell you my requirement : if the file is existed i should display a one message or else i have to send a mail ..
i have the mail logic .. but I'm failed to check file existence .. please... (5 Replies)
Discussion started by: sravan008
5 Replies
LEARN ABOUT ULTRIX
doconfig
doconfig(8) System Manager's Manual doconfig(8)
Name
doconfig - a program to aid system configuration
Syntax
/etc/doconfig [-c config_file] [-e ed_script]
Description
The shell script modifies a copy of the GENERIC configuration file for a new ULTRIX system kernel. The script prompts you for the system
name. If the system name does not currently exist, a system configuration file with that system name is built.
Whether the configuration file is built or not, the script then allows you to edit, configure, and build until both the configuration and
the kernel build run without errors. Additional runs of can be made to tune the configuration further.
When new hardware is added to a system, the configuration file should be updated to reflect the new system configuration. When updating an
existing configuration file or creating a new configuration file with the system must be operating the generic kernel or new hardware may
not be found. To successfully complete the process, follow these steps:
1. Save the running as
2. Move to
3. Reboot the system to single user mode.
4. Check file systems.
5. Mount the file system.
6. Run the program. (When execution is complete, make a note of the message prints showing the path and location of the new
7. Move to
8. Copy the new (from the message noted above) to
9. Reboot the system.
Options
-c The name of the existing configuration file should be supplied without specifying the pathname. This file should exist in the
directory. A new kernel is built using the specified configuration file.
-e When specified, the configuration file is edited by the ed script before building the new kernel.
Files
See Also
ed(1), config(8)
Basic Installation Guide
Guide to System Configuration File Maintenance
RISC doconfig(8)