Test command question


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Test command question
# 1  
Old 07-16-2009
Test command question

Hi all!

I'm new to shell scripting, and I need to do a diff between two dirs. One of them (dir_old) contains many files, and the other (dir_new) contains just a set of 8 files, all starting with MC and extension .CP.

The problem I have is that dir_old contains about 20 files that start with MC and with no extension, so I need to check if the files in dir_new exist before using the diff.

This is what I have so far:

Code:
cd $dir_old
for name in MC*
    do
        if [test -e  $dir_new$name.CP]; then
            diff -s "$name" "$dir_new$name.CP" >> logfile
        fi
    done

Thanks in advance!
# 2  
Old 07-16-2009
Code:
cd $dir_old
dir_new=/some/new/path
for name in MC*
    do
        if [ test -e  ${dir_new}/${name}.CP  ]; then
            diff -s "$name" "${dir_new}/${name}.CP" >> logfile
        fi
    done

I'm not sure about the .CP - you get to fix that. Are there files minus the CP in dir_old, but that have .CP in newdir? That is what your code is doing.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell grammar question: logical OR in test

Hi, I am trying to check if two input files exist before the rest of the scripts is run. Following is the code that I have but it gives me syntax error. if then echo "File not found" else echo "File found" fi (3 Replies)
Discussion started by: nua7
3 Replies

2. Shell Programming and Scripting

Test command

hello, i'v trying to use the TEST command and i have some problems with it. i am trying kill all proccess wich is greater than 25. i started with - ps -f | grep -v TTY | awk '{print $4}' but i dont know how to proceed from here.. 10x a lot, Daniel. (11 Replies)
Discussion started by: dadiT
11 Replies

3. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

4. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

5. Shell Programming and Scripting

FNG Question: Test if remote server has booted

Hello again, I have a script on my media server that wakes up my backup server, performs an 'rsync' backup, then shuts the backup server down. Currently, I have it send the Wake on LAN packet, and sleep for 5 minutes, just to give the backup server time to boot (of course it doesn't take that long,... (11 Replies)
Discussion started by: vwgtiturbo
11 Replies

6. UNIX for Advanced & Expert Users

AIX, Solaris, Linux Test Environment Design Question

AIX, Solaris, Linux Test Environment Design Question We want to set an AIX, Solaris & Linux test environment. Here are the hardware equipments: (1) A Sunfire v100 (or v120), 1GB memory, two 36GB HDD. (2) An IBM pSeries 7026, 1 GB memory, 4 9GB HDD. (3) Five external HDD with SCSI... (1 Reply)
Discussion started by: aixlover
1 Replies

7. Solaris

AIX, Solaris, Linux Test Environment Design Question

AIX, Solaris, Linux Test Environment Design Question We want to set an AIX, Solaris & Linux test environment. Here are the hardware equipments: (1) A Sunfire v100 (or v120), 1GB memory, two 36GB HDD. (2) An IBM pSeries 7026, 1 GB memory, 4 9GB HDD. (3) Five external HDD with SCSI... (4 Replies)
Discussion started by: aixlover
4 Replies

8. Programming

Test command name

I'm very new to C and could use a little help. I'm testing to make sure the command is running as it's proper name, if not then fail. if (strcmp(argv, "xinit") != 0) { fprintf(stdout, "name = %s length = %d\n",argv,l); usage(0); } This works if the command is... (3 Replies)
Discussion started by: nck
3 Replies

9. Shell Programming and Scripting

Another newb question: how to use test for zero-length string ?

Assume $x equals "". If I try: if test -n $x I get the "Expression syntax" error. It works in Linux but not in unix bash. In unix bourne I get "test: argument expected" (4 Replies)
Discussion started by: lumix
4 Replies

10. AIX

question about a 'test' command

Hi all, I have the following script.Can somone explain what it does.Thanks in advance. if test $# -lt 1 then echo "Message" exit 1 fi (2 Replies)
Discussion started by: sam_78_nyc
2 Replies
Login or Register to Ask a Question