11-09-2008
if loop not working in BASH shell
i have this code for a simple if loop:
#!/bin/bash
array="1 2 3 4 5"
array2="5 6 7 8 9"
if [ ${array2[0]} -gt ${array[0]} ]; then
echo "${array2[0]} is greater than ${array[0]}!!"
fi
the error is
./script8: line 9: [: too many arguments
./script8: line 9: [: too many arguments
./script8: line 9: [: too many arguments
./script8: line 9: [: too many arguments
./script8: line 9: [: too many arguments
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Everything else seems to be working, but this isn't. Is it the "cat..." that is wrong of the condition? Thanks.
cat tc_result.txt | while read LINE
do
if
then
let "files_run += 1";
echo "inside the if loop"
# save current filetype
case $LINE... (5 Replies)
Discussion started by: brdholman
5 Replies
2. UNIX for Dummies Questions & Answers
It is happening with my sessions already second time: a 'for'-loop for some reason stop to work as expected.
That means or it is looping without exitting, or it is not loop even once.
Here example of my try when it is not processing even one loop.
You can see, I start new subshell and... (14 Replies)
Discussion started by: alex_5161
14 Replies
3. Shell Programming and Scripting
Hi-
Here is the shell script that for some reason is not returning results:
#! /bin/ksh -
avg() {
AVG=0
typeset SUM=0
if
then
echo "You must have at least two numbers"
else
for NUM in "$*"
do
... (2 Replies)
Discussion started by: koomba
2 Replies
4. Shell Programming and Scripting
Hi Friends,
I am presently migrating shell scripts writter in KSH to SH.I am stuck at this place and i am not able to find a work around:-
Let the script name is x.sh
Below are some of the codes in it...
export abc=hello
export abc=hi
export abc=how
When i am trying to compile the script ... (6 Replies)
Discussion started by: amit.behera
6 Replies
5. Shell Programming and Scripting
Hi,
I am trying to run the factorial script but it’s not working.
The code is mentioned below:
------------------------------------------------------------------
/home/gc> cat fact.sh
#!/bin/bash
# using one command line parameter
factorial=1
for (( number = 1; number <= $1 ;... (3 Replies)
Discussion started by: Technext
3 Replies
6. UNIX for Dummies Questions & Answers
Hi,
I am using a for loop to manipulate files data_1.txt through data_100.txt. The for-loop is set up like this:
for i in {1..100}; do cut -f1 data_$i.txt > output$i.txt
I get the following error message when I run the code:
cannot open `data.txt' for reading: No such file or directory... (4 Replies)
Discussion started by: evelibertine
4 Replies
7. Shell Programming and Scripting
Hi
I'm using this script to transcode videos in an Ubuntu 12.04 machine.
#! /bin/bash
MOVDIR="/media/topaz_1/media/transcodes/transcode_mov/"
MOVDESTDIR="/media/topaz_1/media/transcodes/final_mov/"
DONEFILESDIR="/media/topaz_1/media/transcodes/dv_cache/"... (1 Reply)
Discussion started by: oscarfelson
1 Replies
8. Shell Programming and Scripting
Dear all Linux lover,
I am a new learner to Bash Shell script and I would like to writing a script to to repeat my script.
This mean I would like to have multiple same of result after running the .sh.
#######
TIMES_NO=0
echo -n "Please enter the number for times to repeat ?"
read... (10 Replies)
Discussion started by: Rocky888
10 Replies
9. Shell Programming and Scripting
i have defined a function ln_s() for customizing the ln command in script1.sh.
more script1.sh
echo "Starting Execution"
./script2.sh
echo "End of Execution"
ln_s(){
] && return
ln -s "$1" "$2"
}
My script1.sh executes another script2.sh which has the following entry
more script2.sh... (12 Replies)
Discussion started by: mohtashims
12 Replies
10. Shell Programming and Scripting
I have a loop with cases
I am working on Bourne shell
for file in *.${Today}*.csv *.${Today}*.txt\
do
case ${file} in
sun_detail)
do something
;;
sum)
do something
;;
mod)
do something
;;
*)
do something
;; (5 Replies)
Discussion started by: digioleg54
5 Replies
LEARN ABOUT PHP
array_intersect_ukey
ARRAY_INTERSECT_UKEY(3) 1 ARRAY_INTERSECT_UKEY(3)
array_intersect_ukey - Computes the intersection of arrays using a callback function on the keys for comparison
SYNOPSIS
array array_intersect_ukey (array $array1, array $array2, [array $...], callable $key_compare_func)
DESCRIPTION
array_intersect_ukey(3) returns an array containing all the values of $array1 which have matching keys that are present in all the argu-
ments.
PARAMETERS
o $array1
- Initial array for comparison of the arrays.
o $array2
- First array to compare keys against.
o $...
- Variable list of array arguments to compare keys against.
o $key_compare_func
- The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to
be respectively less than, equal to, or greater than the second.
int callback (mixed $a, mixed $b)
RETURN VALUES
Returns the values of $array1 whose keys exist in all the arguments.
EXAMPLES
Example #1
array_intersect_ukey(3) example
<?php
function key_compare_func($key1, $key2)
{
if ($key1 == $key2)
return 0;
else if ($key1 > $key2)
return 1;
else
return -1;
}
$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4);
$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8);
var_dump(array_intersect_ukey($array1, $array2, 'key_compare_func'));
?>
The above example will output:
array(2) {
["blue"]=>
int(1)
["green"]=>
int(3)
}
In our example you see that only the keys 'blue' and 'green' are present in both arrays and thus returned. Also notice that the values for
the keys 'blue' and 'green' differ between the two arrays. A match still occurs because only the keys are checked. The values returned are
those of $array1.
SEE ALSO
array_diff(3), array_udiff(3), array_diff_assoc(3), array_diff_uassoc(3), array_udiff_assoc(3), array_udiff_uassoc(3), array_diff_key(3),
array_diff_ukey(3), array_intersect(3), array_intersect_assoc(3), array_intersect_uassoc(3), array_intersect_key(3).
PHP Documentation Group ARRAY_INTERSECT_UKEY(3)