Sponsored Content
Operating Systems Linux Red Hat Values in array are not able to be used one by one Post 302806335 by ramsavi on Monday 13th of May 2013 02:13:05 AM
Old 05-13-2013
Values in array are not able to be used one by one

hey,i stored the value of an sql query in an array and then tried to use that
value in while loop. actually my array will have two or more values, then according to the values i have to display result.
Code:
#!/bin/bash -xv

val_1=$( sqlplus -s rte/rted1@rel75d1 << EOF
set heading off
select max(istat_id) from cvt_istats;
exit
EOF
)
 sqlplus -s rte/rted1@rel75d1 << EOF
++ sqlplus -s rte/rted1@rel75d1
+ val_1='
          999'
echo "val_1: $val_1"
+ echo 'val_1:
          999'
val_1:
          999

nohup ./cvt -f MediationSources.xml &
sleep 60
+ sleep 60
+ nohup ./cvt -f MediationSources.xml
nohup: appending output to `nohup.out'

declare -a arr
+ declare -a arr
arr=$( sqlplus -s rte/rted1@rel75d1 << EOF
set heading off
select source_id from cvt_istats where istat_id > $val_1;
exit
EOF
)
 sqlplus -s rte/rted1@rel75d1 << EOF
++ sqlplus -s rte/rted1@rel75d1
+ arr='
         1
         2'
echo "val_2: $arr"
+ echo 'val_2:
         1
         2'
val_2:
         1
         2

i=0
+ i=0
len=${#arr[*]}
+ len=1
echo $len
+ echo 1
1

while [ $len -gt $i ]
do
  if [ ${arr[$i]} == 1 ]
  then
    echo "%D% FILE MASK PASS"
  elif [ ${arr[$i]} == 2 ]
  then
    echo "%C% FILE MASK PASS"
  else
   echo "FILE MASK FAIL"
  fi

  i=$(( $i + 1 ))
done
+ '[' 1 -gt 0 ']'
+ '[' 1 2 == 1 ']'
./linux8.sh: line 29: [: too many arguments
+ '[' 1 2 == 2 ']'
./linux8.sh: line 32: [: too many arguments
+ echo 'FILE MASK FAIL'
FILE MASK FAIL
+ i=1
+ '[' 1 -gt 1 ']'

but in the array both 1 2 are selected and then it is not able to compare

what should i do

Thanks

---------- Post updated at 01:13 AM ---------- Previous update was at 01:11 AM ----------

my code without xv looks like this

Code:
#!/bin/bash -xv

val_1=$( sqlplus -s rte/rted1@rel75d1 << EOF
set heading off
select max(istat_id) from cvt_istats;
exit
EOF
)
echo "val_1: $val_1"

nohup ./cvt -f MediationSources.xml &
sleep 60

declare -a arr
arr=$( sqlplus -s rte/rted1@rel75d1 << EOF
set heading off
select source_id from cvt_istats where istat_id > $val_1;
exit
EOF
)
echo "val_2: $arr"

i=0
len=${#arr[*]}
echo $len

while [ $len -gt $i ]
do
  if [ ${arr[$i]} == 1 ]
  then
    echo "%D% FILE MASK PASS"
  elif [ ${arr[$i]} == 2 ]
  then
    echo "%C% FILE MASK PASS"
  else
   echo "FILE MASK FAIL"
  fi

  i=$(( $i + 1 ))
done


Last edited by Scott; 05-13-2013 at 03:18 AM.. Reason: CODE tags NOT ICODE tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

array values in a command

:confused: I am a newbie to scripting so I am probably missing something but when this function runs it just returns blank lines, but if I surround the sed with a print it returns the full commands that can be excuted on the command line ne_ip_change() { set -A NE `$CAT /tmp/ne_list` ... (3 Replies)
Discussion started by: eeisken
3 Replies

2. UNIX for Dummies Questions & Answers

Assigning values to an array

The way I've been using arrays currently have been: #!/bin/ksh set -A myArray myArray=value1 myArray=value2 myArray=value3 myArray=value4 Is there a way I can assign values to an array that will automatically place the value into the next element in the array like: myArray=value1... (4 Replies)
Discussion started by: yongho
4 Replies

3. UNIX for Dummies Questions & Answers

incorrect array values

I have a file with 2 lines and 3 filelds -bash-3.00$ cat del_old_files.cfg $DBA_WORK_DIR *sybdba* 30 $DBA_LOG_DIR *sybdba* 30 I have tried to set up arrays for each field (bash shell) declare -a dirArray=`cut -d' ' -f1 < del_old_files.cfg` declare -a nameArray=`cut -d' ' -f2 <... (6 Replies)
Discussion started by: jhillier
6 Replies

4. Shell Programming and Scripting

How to use array values after the loop.

- I m retreving values from database and wish to use those values later in my shell script. I m placing these values in an array da_data but outside loop array is empty.Problem is its treating array as local inside loop hence array is empty outside loop. Plz go through the script and suggest how... (1 Reply)
Discussion started by: Devesh5683
1 Replies

5. Shell Programming and Scripting

Assigning the values to an Array

hi every body, i donot know how to assign a array varible with a file see i having file more file property1 Name property2 Address the above two line are tab Space seperated between the property and its value i want to seperate it and assign to... (1 Reply)
Discussion started by: kkraja
1 Replies

6. UNIX for Dummies Questions & Answers

Compare array values

# tail myprocesses.txt 178 processes at Tue Oct 21 14:33:01 IST 2008 16 MySQL processes at Tue Oct 21 14:33:01 IST 2008 175 processes at Tue Oct 21 14:36:01 IST 2008 60 MySQL processes at Tue Oct 21 14:36:01 IST 2008 192 processes at Tue Oct 21 14:39:01 IST 2008 64 MySQL processes at Tue Oct... (2 Replies)
Discussion started by: shantanuo
2 Replies

7. Shell Programming and Scripting

Store values in an Array

Hi all. Well, I have the next code: I need to make an array with the values I have in the bucle, but just don't get it... Question is, how can I store in an array that values, and how can I display them with echo? (8 Replies)
Discussion started by: crcbad
8 Replies

8. Shell Programming and Scripting

PHP: Search Multi-Dimensional(nested) array and export values of currenly worked on array.

Hi All, I'm writing a nagios check that will see if our ldap servers are in sync... I got the status data into a nested array, I would like to search key of each array and if "OK" is NOT present, echo other key=>values in the current array to a variable so...eg...let take the single array... (1 Reply)
Discussion started by: zeekblack
1 Replies

9. Shell Programming and Scripting

reading values into an array

I have this portion of a script and it works: base_config="A B C D E" for field in $base_config do var=`echo $field` ((i=$i+1)) done I get an array of var=A, var=B, and so on. What if I have this example with white space and want to put it into an array while... (1 Reply)
Discussion started by: djehresmann
1 Replies

10. Red Hat

How to check for values in array?

i stored some values in array , then i traverse through the array and check for some values and if they exist then echo success. let us consider that in our array we stored values from an sql query like this #!/bin/bash declare -a arr arr=$( sqlplus -s rte/rted2@rel76d2 << EOF set... (1 Reply)
Discussion started by: ramsavi
1 Replies
SQLSRV_PREPARE(3)														 SQLSRV_PREPARE(3)

sqlsrv_prepare - Prepares a query for execution

SYNOPSIS
mixed sqlsrv_prepare (resource $conn, string $sql, [array $params], [array $options]) DESCRIPTION
Prepares a query for execution. This function is ideal for preparing a query that will be executed multiple times with different parameter values. PARAMETERS
o $conn - A connection resource returned by sqlsrv_connect(3). o $sql - The string that defines the query to be prepared and executed. o $params - An array specifying parameter information when executing a parameterized query. Array elements can be any of the following: oA literal value oA PHP variable oAn array with this structure: array($value [, $direction [, $phpType [, $sqlType]]]) The following table describes the elements in the array structure above: Array structure +----------------------+---------------------------------------------------+ | Element | | | | | | | Description | | | | +----------------------+---------------------------------------------------+ | $value | | | | | | | A literal value, a PHP variable, or a PHP by-ref- | | | erence variable. | | | | |$direction (optional) | | | | | | | One of the following SQLSRV constants used to | | | indicate the parameter direction: SQL- | | | SRV_PARAM_IN, SQLSRV_PARAM_OUT, SQL- | | | SRV_PARAM_INOUT. The default value is SQL- | | | SRV_PARAM_IN. | | | | | $phpType (optional) | | | | | | | A SQLSRV_PHPTYPE_* constant that specifies PHP | | | data type of the returned value. | | | | | $sqlType (optional) | | | | | | | A SQLSRV_SQLTYPE_* constant that specifies the | | | SQL Server data type of the input value. | | | | +----------------------+---------------------------------------------------+ o $options - An array specifing query property options. The supported keys are described in the following table: Query Options +-----------------------+--------------------------------------+---+ | Key | | | | | | | | | Values | | | | | | | | Description | | | | | | +-----------------------+--------------------------------------+---+ | QueryTimeout | | | | | | | | | A positive integer value. | | | | | | | | Sets the query timeout in seconds. | | | | By default, the driver will wait | | | | indefinitely for results. | | | | | | |SendStreamParamsAtExec | | | | | | | | | | | | | TRUE or FALSE (the default is TRUE) | | | | | | | | Configures the driver to send all | | | | stream data at execution ( TRUE), or | | | | to send stream data in chunks ( | | | | FALSE). By default, the value is set | | | | to TRUE. For more information, see | | | | sqlsrv_send_stream_data(3). | | | | | | | Scrollable | | | | | | | | | SQLSRV_CURSOR_FORWARD, SQLSRV_CUR- | | | | SOR_STATIC, SQLSRV_CURSOR_DYNAMIC, | | | | or SQLSRV_CURSOR_KEYSET | | | | | | | | See Specifying a Cursor Type and | | | | Selecting Rows in the Microsoft SQL- | | | | SRV documentation. | | | | | | +-----------------------+--------------------------------------+---+ RETURN VALUES
Returns a statement resource on success and FALSE if an error occurred. EXAMPLES
Example #1 sqlsrv_prepare(3) example This example demonstrates how to prepare a statement with sqlsrv_prepare(3) and re-execute it multiple times (with different param- eter values) using sqlsrv_execute(3). <?php $serverName = "serverNamesqlexpress"; $connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false) { die( print_r( sqlsrv_errors(), true)); } $sql = "UPDATE Table_1 SET OrderQty = ? WHERE SalesOrderID = ?"; // Initialize parameters and prepare the statement. // Variables $qty and $id are bound to the statement, $stmt. $qty = 0; $id = 0; $stmt = sqlsrv_prepare( $conn, $sql, array( &$qty, &$id)); if( !$stmt ) { die( print_r( sqlsrv_errors(), true)); } // Set up the SalesOrderDetailID and OrderQty information. // This array maps the order ID to order quantity in key=>value pairs. $orders = array( 1=>10, 2=>20, 3=>30); // Execute the statement for each order. foreach( $orders as $id => $qty) { // Because $id and $qty are bound to $stmt1, their updated // values are used with each execution of the statement. if( sqlsrv_execute( $stmt ) === false ) { die( print_r( sqlsrv_errors(), true)); } } ?> NOTES
When you prepare a statement that uses variables as parameters, the variables are bound to the statement. This means that if you update the values of the variables, the next time you execute the statement it will run with updated parameter values. For statements that you plan to execute only once, use sqlsrv_query(3). SEE ALSO
sqlsrv_execute(3), sqlsrv_query(3). PHP Documentation Group SQLSRV_PREPARE(3)
All times are GMT -4. The time now is 08:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy