10-09-2019
You never used code i posted, and you have expanded your code with pipes and line counts.
If [[ 'ls $INPUTDIR/abc*.dat | wc -l > 0' ]] -> will always evaluate to true
Without test it will default on -n, at least on bash here debian linux.
The command inside single quotes is never executed, just checked if the length of string passed 'ls $INPUTDIR/abc*.dat | wc -l > 0' is greater then zero.
This will always be true, and your code will never hit else condition.
if should be lower case.
Ending the if clause is done with fi, not another if as you wrote.
The fiile1 is a hard-coded file name and will be removed when you execute the script from current running directory, deleting the file if it exists.
I'm not sure what are you are trying to write here, hopefully i cleared some or all misunderstanding.
Also MiG suggested an alternative with custom function found in thread linked.
Can you be more precise about your exact requirement, with input and output expected or desired effect of your code ?
Please specify your operating system and shell details as well.
Hope that helps.
Regards
Peasant.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I need to prompt for a response from a user to enter a path
read dest_dir?"Please Enter Directory :"
How do I do this until a valid directory is entered by the user. I can use
to check the existence of the directory. However when I try the following I cannot get it to work.
while ... (2 Replies)
Discussion started by: jerardfjay
2 Replies
2. Shell Programming and Scripting
I'm trying to write a script that identifies whether a directory of the form AWL.????????.IP exists. I have one that exists which is AWL.05301032.IP.
When I test like this: If ]
I get true, but when I test like this:
If ]
Or like this
If ]
Or any other variation of wild cards, I... (4 Replies)
Discussion started by: philplasma
4 Replies
3. UNIX for Dummies Questions & Answers
Hi.
I what to write a make file that inside a target I want to check if a directory exists.
some like:
### make
a:
if ;then
<command 1>
else
<command 2>
fi
### make end
Thanks a lot
---------------------- (2 Replies)
Discussion started by: zivsegal
2 Replies
4. Shell Programming and Scripting
Hello:
Can someone please help me figure out what is wrong here, my script does not move on to the "else" part even though there is no .ssh directory on my remote server:
$more putkey.sh
#!/bin/ksh
for server in `cat list`
do
if ; then
cat $HOME/.ssh/id_rsa.pub |ssh $server ' cat >>... (4 Replies)
Discussion started by: Sara-sh
4 Replies
5. Shell Programming and Scripting
Hey guys im trying to check if the directory exists
i get a syntax error on the elif statement iv tried using else and still same result im not sure. If the directory does not exist can i just insert mkdir /tmp/old under the elif once that part gets working
if ; then
#do nothing
elif
echo... (20 Replies)
Discussion started by: musicmancanora
20 Replies
6. Shell Programming and Scripting
cp $PATHLOGS/$DATE/*.* $TMP/logs_tmp/
cp $PATHLOGS/$DATE1/*.* $TMP/logs_tmp/
Before copying the files I have to check if the directory $DATE1 and $DATE2 exists.
If directory exists then, check if the folder contains some files.
if the file exists then, check if the file size is greater... (3 Replies)
Discussion started by: sandy1028
3 Replies
7. Shell Programming and Scripting
I want to perform SQL *Loader operation only if a file named "load.txt" exists in a directory "/home/loc/etc". Please help how to check this with a if condition. (8 Replies)
Discussion started by: vel4ever
8 Replies
8. Shell Programming and Scripting
Hi,
I am using solaris 10 OS and bash shell.just checking for small code snippet which follows below.
/export/home/vomappservers/spa/common/5.0
/export/home/vomappservers/spa/common/scripts
/export/home/vomappservers/spa/tools
/export/home/vomappservers/spa/scm5.0/SCCS... (5 Replies)
Discussion started by: muraliinfy04
5 Replies
9. Shell Programming and Scripting
Hi Gurus,
I have a requests to find if all the file in the filelist exist in certain directory.
example:
my filelist
abc
def
ddd
cde
afg
how can I find these 5 files exists at director /home/abc
Thanks in advance (7 Replies)
Discussion started by: ken6503
7 Replies
10. Shell Programming and Scripting
Hi guys,
I am beginner trying to learn unix. So any help is welcomed.
My requirement is to check whether is a file exists in a particular directory or not.
The directory path and filename are taken dynamically with user interaction. So the program should continue only if the $filename... (1 Reply)
Discussion started by: maris_markur
1 Replies
TEST(1) General Commands Manual TEST(1)
NAME
test - set status according to condition
SYNOPSIS
test expr
DESCRIPTION
Test evaluates the expression expr. If the value is true the exit status is null; otherwise the exit status is non-null. If there are no
arguments the exit status is non-null.
The following primitives are used to construct expr.
-r file True if the file exists (is accessible) and is readable.
-w file True if the file exists and is writable.
-x file True if the file exists and has execute permission.
-e file True if the file exists.
-f file True if the file exists and is a plain file.
-d file True if the file exists and is a directory.
-s file True if the file exists and has a size greater than zero.
-t fildes True if the open file whose file descriptor number is fildes (1 by default) is the same file as /dev/cons.
s1 = s2 True if the strings s1 and s2 are identical.
s1 != s2 True if the strings s1 and s2 are not identical.
s1 True if s1 is not the null string. (Deprecated.)
-n s1 True if the length of string s1 is non-zero.
-z s1 True if the length of string s1 is zero.
n1 -eq n2 True if the integers n1 and n2 are arithmetically equal. Any of the comparisons -ne, -gt, -ge, -lt, or -le may be used in place
of -eq. The (nonstandard) construct -l string, meaning the length of string, may be used in place of an integer.
These primaries may be combined with the following operators:
! unary negation operator
-o binary or operator
-a binary and operator; higher precedence than -o
( expr ) parentheses for grouping.
The primitives -b, -u, -g, and -s return false; they are recognized for compatibility with POSIX.
Notice that all the operators and flags are separate arguments to test. Notice also that parentheses and equal signs are meaningful to rc
and must be enclosed in quotes.
EXAMPLES
Test is a dubious way to check for specific character strings: it uses a process to do what an rc(1) match or switch statement can do. The
first example is not only inefficient but wrong, because test understands the purported string "-c" as an option.
if (test $1 '=' "-c") echo OK # wrong!
A better way is
if (~ $1 -c) echo OK
Test whether is in the current directory.
test -f abc -o -d abc
SOURCE
/sys/src/cmd/test.c
SEE ALSO
rc(1)
TEST(1)