TEST Command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting TEST Command
# 8  
Old 02-22-2011
Hello,

I can't figure this out ... I need help please.

How to write a test that will read and check the content of $lst_proto and $lst_proto_old and see if the choice of $prototype exist in $lst_proto or in $lst_proto_old ?

Otherwise I need the script to say that the choice selected is not valid.

thanks
# 9  
Old 02-22-2011
Code:
#!/usr/bin/ksh
lst_proto=/whatever/your_list
lst_proto_old=/whatever/your_list.old
echo "Enter your prototype:"
read prototype
RES=$(grep -l "$prototype" ${lst_proto} ${lst_proto_old} 2>/dev/null)
[[ -z "RES" ]] && echo "Prototype not valide" || echo "Prototype can be found in $RES"


Last edited by ctsgnb; 02-22-2011 at 12:40 PM..
# 10  
Old 02-22-2011
Hi,

sorry ctsgnb, but the code given doesn't work.


$lst_proto and $lst_proto_old are list of configuration files. That means $lst_proto and $lst_proto_old may have some multiple choice.

ex :
Code:
$lst_proto = 
sonic
meag

Code:
$lst_proto_old =
ninte
mario

How to write a test that could read $lst_proto and $lst_proto_old to check if $prototype exist at least on one of the variables, otherwise exit.

Thanks for your help

---------- Post updated at 05:13 AM ---------- Previous update was at 05:04 AM ----------

Hi,

as I read some other posts, it seems that a case statement usually works best to check the content of variables. Does anyone can say somethings about it ?

---------- Post updated at 06:13 AM ---------- Previous update was at 05:13 AM ----------

Hello,

I do not know if what I've done is the way that it should be done but I solved my problem.

I have replaced $lst_proto and $lst_proto_old by temporary files. Here is what I have done. It could help someone ... Do not hesitate to comment my work ...

Code:
cat ${dir_config}/*.cfg | grep "#name_transfert#" | cut -d " " -f"2" | sort | tee ${fic_lst_proto}

nb_proto_old=$(ls ${dir_config}/_HISTO_FIC_CFG/*.cfg | wc -l )

        if [ -z ${nb_proto_old} ];
        then
                echo " "
                echo "--------OLD PROTOTYPE-------------"
                echo " "
                cat ${dir_config}/_HISTO_FIC_CFG/*.cfg | grep "#name_transfert#" | cut -d " " -f"2" | sort | tee ${fic_lst_proto_old}
                echo " "
         fi

                echo "Please choose your configuration file : \c"

                read prototype

                echo "-------------------------------------------"
                echo "You have choosen : ${prototype} \n"
                echo "-------------------------------------------"
                echo " "

           if [ `cat ${fic_lst_proto} | grep ${prototype}` ] || [ `cat ${fic_lst_proto_old} | grep ${prototype}` ]
           then

           else
                     echo "\n Error while reading configuration file!\n\n"
                     exit
           fi

Thanks all for your help
# 11  
Old 02-22-2011
Your code could be enhanced a lot ... but we would need a bit more clue about the cfg file you have.
Could you please post the result of the following commands :
Code:
ls ${dir_config}/_HISTO_FIC_CFG/*.cfg
ls ${dir_config}/*.cfg
cat ${dir_config}/_HISTO_FIC_CFG/*.cfg
cat ${dir_config}/*.cfg

# 12  
Old 02-24-2011
Hello,

As requested, here is the result :

Code:
ls ${dir_config}/_HISTO_FIC_CFG/*.cfg

NATIVE_HIN_SATURNE.cfg
NATIVE_SONIC.cfg
NATIVE_TAR_PLUTON.cfg
VITRINE_GL4_SATURNE.cfg
VITRINE_HM_PLUTON.cfg
VITRINE_PLUTON.cfg

Code:
ls ${dir_config}/*.cfg

NATIVE_HIN_MERCURE.cfg
NATIVE_MERCURE.cfg
NATIVE_TAR_CELCIUS.cfg
VITRINE_GL4_GRID.cfg
VITRINE_HM_SUN.cfg
VITRINE_SU2P4V1.cfg

Code:
cat ${dir_config}/_HISTO_FIC_CFG/*.cfg
cat ${dir_config}/*.cfg


#tronc_staf# /OPERATIONNEL/SUN

#branche# ALLEGES_BEST
#branche# TRACES
#nbr_feuille_par_#branche# PHYSICAL_MODEL/FORECAST 98

#branche#supprime# RESTART_SAT
#brancheSpecifique# RESTART_SAT RESTARTICE RESTARTICE
#brancheSpecifique# RESTART_SAT RESTART RESTART

The content of the configuration files do not change much. All info needed is between #tronc_staf# and #branche#.

So far I am just trying to simplify the first part of the script and make a strong condition that send warning or exit if the configuration file select is not a the list or if you type ENTER instead of selecting a file print on screen.

Info :

I do not need
Code:
#branche#supprime# RESTART_SAT

and

NOTE : for #brancheSpecifique# I need the last part of the line

Code:
#brancheSpecifique# RESTART_SAT RESTART RESTART : I am keeping the last RESTART

Thanks
# 13  
Old 02-24-2011
Could you please explain as clearly as possible what you are trying to achieve ?

So you have many config files like

${dir_config}/_HISTO_FIC_CFG/*.cfg
${dir_config}/*.cfg

So you want to be prompted for a prototype name, and then what you want the scripts to do ?

Do you want it to display the name of the config file in which the prototype has been found ?

Code:
echo "Enter prototype name:"
read prototype
grep -l "$prototype" ${dir_config}/_HISTO_FIC_CFG/*.cfg ${dir_config}/*.cfg

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