TEST Command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting TEST Command
# 1  
Old 02-17-2011
TEST Command

Hello,

I need help with a test command.

Here is what I am trying to do :

I've got an interactive script that check if configuration files exist on 2 different directories, then all configuration files are print on screen by a short name.

My problem is when you type a "wrong name" or "enter" instead of one the short name given.

How can I get create a test that will check to see if you have exactly choosen one of the configuration files given ?

Code:
lst_proto=$(cat ${rep_config}/*.cfg | grep "#name_transfert#" | cut -d " " -f"2" | sort)
        echo "${lst_proto} "

                lst_proto_old=$(cat ${rep_config}/_HISTO_FIC_CFG/*.cfg | grep "#name_transfert#" | cut -d " " -f"2" | sort)
                if [ -z ${nb_proto_old} ];
        then
                echo " "
                echo "--------OLD PROTOTYPE-------------"
                echo " "
                echo "${lst_proto_old} "
                echo " "
        fi

        echo "Please choose your configuration file : \c"

        read prototype

        echo "-------------------------------------------"
        echo "You have choosen : ${prototype} \n"
        echo "-------------------------------------------"
        echo " "
#------------------------complet name files------------------
        cd ${rep_config}
        nom_cfg=$(${prototype}.cfg)

                if [ "#"${nom_cfg}"#" == "##" ];
                then
#------------------------OLD complet name files----------------------------
                        rep_config="${rep_config}/_HISTO_FIC_CFG"
                        cd ${rep_config}
                        nom_cfg=$(${prototype}.cfg)
                fi

I don't even know if it's possible.

Thanls for your help
# 2  
Old 02-17-2011
Just do a string comparison between ${prototype} and each of the config names, if its wrong then return to the top of the function.
# 3  
Old 02-17-2011
HI,

I try to compare ${prototype} with ${lst_proto} and ${lst_proto_old} but that doesn't work ! any idea ?

Thanks
# 4  
Old 02-17-2011
Quote:
Originally Posted by Aswex
HI,

I try to compare ${prototype} with ${lst_proto} and ${lst_proto_old} but that doesn't work ! any idea ?

Thanks
after you perform the line "lst_proto=$(cat ${rep_config}/*.cfg | grep "#name_transfert#" | cut -d " " -f"2" | sort)"

do an "echo ${lst_proto}"

This variable may have more than one result in it which means you will have to iterate through and compare each result against ${prototype}
# 5  
Old 02-21-2011
Hi robfwauk,

sorry for the delay, I was away few days.

Thanks for your help, but do you know how I could iterate through and compare each result against ${prototype} ?

I do not know how I could do this ...


Thanks.
# 6  
Old 02-21-2011
This is an example of how you would iterate through a list of items:

Code:
for item in ${list_of_items}; do
    if [[ $item = teacup ]]; then
         echo "Five bucks for the $item"
    else
         echo "That $item is not for sale, sorry"
    fi
done

Apply it to your circumstance.
# 7  
Old 02-21-2011
Have you considered using a select statement:

Code:
PS3="Please choose your configuration file :"
select prototype in $(....your code here....)
do
   if [[ -n $prototype ]]
   then
        echo "You selected $prototype"
        break;
    else
        echo "Invalid choice: $REPLY"
    fi
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Evaluation of test command

Could somebody please explain to me why and how the highlighted line(s) (?) of code puts the "test" evaluation into "result" and then to $enable_static ? Or does not ? I did comment out the original code and changed it to what I feel is less cryptic , but the "result" is still wrong =... (3 Replies)
Discussion started by: anne
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. UNIX for Dummies Questions & Answers

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... (1 Reply)
Discussion started by: fpp666
1 Replies

6. 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

7. Shell Programming and Scripting

Help with test command

Plese help me on the below query. for j in *.20071231* *.ctl *.dat do ( if then cp "$base/*.*" "$base1" fi ) done My requirement is for all files that has extension *.20071231* *.ctl *.dat should be copied to another folder. But those with caaa.20071231.log... (7 Replies)
Discussion started by: sussane
7 Replies

8. Shell Programming and Scripting

TEST command

I have been looking into searching various files to display output. The search criteria will be a month and year to output various numbers in the files. is there any way to do this with the TEST function or would it have to be another way? (4 Replies)
Discussion started by: amatuer_lee_3
4 Replies

9. AIX

Test command

Hello, I am trying to add some tests to existing code. The code already contains some test commands. An example is as follows... ] then Does anyone know the purpose of the double equals? I would have used a single equals sign... (2 Replies)
Discussion started by: JWilliams
2 Replies

10. UNIX for Dummies Questions & Answers

the TEST command

Hi everyone, I am new to UNIX and scripting, and I have some problems with the test command. when i try to execute the command: test 20070327.gz > 20070320.gz i try to make a charachter string comparison between the two strings or the two files, to make sure that 20070327.gz is greater than... (2 Replies)
Discussion started by: marwan
2 Replies
Login or Register to Ask a Question