04-05-2002
The test command is your best bet.
Look at the bottom -z is for zero test and -n is for non-zero test.
man test
test(1) test(1)
NAME
test - condition evaluation command
SYNOPSIS
test expr
[ expr ]
DESCRIPTION
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.
10 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
Hi,
I need your help.
How can I create an empty filename with a specific size, in hp-ux?
Regards,
Mizi (2 Replies)
Discussion started by: Mizi
2 Replies
2. Shell Programming and Scripting
What is the command to empty an already existing file.
please provide me.i used Touch cmd to empty the file.but it changing the time only. (4 Replies)
Discussion started by: laknar
4 Replies
3. UNIX for Dummies Questions & Answers
hi all:
my solaris FIND does not support
find myFolder -type d -empty
how can i find the empty folders?
thanks! (7 Replies)
Discussion started by: lasse
7 Replies
4. UNIX for Dummies Questions & Answers
AIX 5.3 / KSH
I have a Java application which creates a log file a.log. I have a KSH script which does the following action
cp a.log /directory2/b.log
> a.log
After this the file size goes to 0 as per "ls -l"
Then next time when the application writes into this file, the file size... (4 Replies)
Discussion started by: firdousamir
4 Replies
5. Shell Programming and Scripting
hi
how can I determine, if a file is empty or not?I am using read line clause.
The script should be like:
while read line
do
if(file is empty) then;
......
done < $blacklist (1 Reply)
Discussion started by: tjay83
1 Replies
6. UNIX for Dummies Questions & Answers
Hi All,
I am checking for a empty input file to do some further action , but I am getting exit status 0 in both the cases , for empty and non empty file both.
The value of $? is coming 0 in if part also and else part too.
#!/bin/ksh
if ]; then
echo "data"
# exit 0
echo "$?"
else... (4 Replies)
Discussion started by: mavesum
4 Replies
7. Shell Programming and Scripting
how can i use while loop ?
while file is empty do....
if not empty do .....
in bash (1 Reply)
Discussion started by: Trump
1 Replies
8. Shell Programming and Scripting
Hi All,
I have a piece of perl code in which I DON'T want to delete a file rather empty out the contents, here is the code -
if ( unlink("$opt_b") == 1 ) {
print_log( "$opt_b deleted", 1 );
}else {
print_log( "Could not delete $opt_b:$!", 1 );
... (5 Replies)
Discussion started by: jacki
5 Replies
9. Shell Programming and Scripting
Hi there,
I'm just starting out with shell scripting and I'm trying to make a test where the script will basically run yum check-update to find out if the server has any available and if it does it e-mails me but if not it will just stop there.
I have it working if there are actually... (7 Replies)
Discussion started by: Imnewtothis
7 Replies
10. Shell Programming and Scripting
The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format:
input
chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18
chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies
LEARN ABOUT HPUX
secure_sid_scripts
secure_sid_scripts(5) File Formats Manual secure_sid_scripts(5)
NAME
secure_sid_scripts - controls whether setuid and setgid bits on scripts are honored
VALUES
Failsafe
Default
Allowed values
Recommended values
DESCRIPTION
This tunable controls whether and bits on executable scripts have any effect. Honoring on scripts make a system vulnerable to attack by
malicious users.
The default value for this variable is 1, indicating that bits are to be ignored by the execve(2) system call for higher security. The
tunable can be set to 0 for a compatibility with older releases at the expense of security. Hewlett-Packard strongly recommends that you
not change the value of this tunable unless there is an urgent need to do so.
When a script with bits is executed, the kernel generates the following error message to both the terminal controlling and the system log.
(To view the error message, use dmesg(1M) or inspect
Who is Expected to Change This Tunable?
Administrator.
Restrictions on Changing
Changes to this tunable take effect for new scripts started after the change.
When Should the Value of This Tunable Be Changed?
This tunable controls operational modes rather than data structure sizes and limits. The appropriate setting for a system depends on
whether you consider security or compatibility to be most important.
A value of is compatible with previous releases of HP-UX, but it is also less secure.
A value of provides security against race condition attacks exploiting scripts.
What Are the Side Effects of Changing the Value
This tunable controls only executable scripts (not programs) with bit set. HP-UX does not ship with any such scripts. If the customer
wishes to use scripts, third party applications such as or can be used. Alternatively, the shell script can be wrapped in a simple C pro-
gram that runs the shell script with appropriate permissions:
What Other Tunable Values Should Be Changed at the Same Time?
None.
WARNINGS
None. All HP-UX kernel tunable parameters are release specific. This parameter may be removed or have its meaning changed in future
releases of HP-UX.
Installation of optional kernel software, from HP or other vendors, may cause changes to tunable parameter values. After installation,
some tunable parameters may no longer be at the default or recommended values. For information about the effects of installation on tun-
able values, consult the documentation for the kernel software being installed. For information about optional kernel software that was
factory installed on your system, see at
FILES
AUTHOR
was developed by HP.
SEE ALSO
chmod(1), execve(2), kctune(1M).
Tunable Kernel Parameters secure_sid_scripts(5)