Yes, the reversed date string compare works but the problem is that I have to add this logic to a bash script and the bash script will not handle "-gt" when comparing strings.
If there was a problem with the size of the integer, I should also have a problem changing their values, adding to them, But this code runs without error except when it is time to compare the variables.
If there was a problem with the size of the integer, I should also have a problem changing their values, adding to them, But this code runs without error except when it is time to compare the variables.
Try using the shell keyword [[ instead of the [ builtin:
Or better use the (( )) compound command:
If you're on Solaris, you may consider using the POSIX shell /usr/xpg4/bin/sh instead of this old version of bash,
notice that with that shell you should use the standard syntax: [ expression ].
It works, I tried both ways with bash (I have no option on the shell selection) and they both worked.
Could you explain the difference between one set of square brackets vs 2 sets and how come I can use the ">" symbol as "greater than" in bash when using 2 sets of parentheses?
1. The [ and the test builtin commands. In this context (after the [ and the test command) parameter expansion, word splitting and pathname expansion are performed[1]. So beware of the following situation when using the [ and the test commands:
2. The [[ non standard (ksh93, zsh and bash) compound command. Parameter expansion is performed inside [[ ]].
No word splitting and pathname expansion are performed[2]. Support more operators.
Consider the following:
- no need to quote unset variables or variables with null values or values containing IFS characters:
- new versions of bash support new operators:
- readable operators for logical comparison:
3. The compound command ((expression)). From the manual pages for bash[3]:
Quote:
The expression is evaluated according to the rules described below under ARITHMETIC
EVALUATION. If the value of the expression is non-zero, the return status is 0; oth-
erwise the return status is 1. This is exactly equivalent to let "expression".
And as far as your particular problem is concerned it seems like a limitation of the old version of bash you're using,
your code works with recent versions of the bash shell.
[1] For more details see the manual pages for bash, the section Shell Builtin Commands and CONDITIONAL EXPRESSIONS.
[2] For more details see the manual pages for bash, the section Compound Commands. Tilde expansion, arithmetic expansion, command substitution, process substitution, and quote removal are also performed.
[3] For more information see:
Hi,
I can't figure out what I'm missing. I'm running a query to see if there are any streams recording on my DVR before starting a scripted update. I'm guessing that it is viewing $VIDEO as a string instead of an int. I've tried everything I saw on google but it still comes back as $VIDEO is... (8 Replies)
Would like to compare 2 XML Strings which has certain known fields changed. For example, Date field will always have differences. When comparing both strings, skip/mask all the occurring Date Field's `DtField1` and `DtField2`
Note: these are not formatted xml format.
File1:
... (1 Reply)
Hy friends, I am newbie to bash scripting, can anyone explain how b=${a/23/BB} # Substitute "BB" for "23". this line converts "b" into string and and "d" into Integer. Thanks in advance (4 Replies)
Hi,
I am working in bash in Mac OSX, I have following 'input.txt' file:
<INFO> HypoTestTool: >>> Done running HypoTestInverter on the workspace combined
<INFO> HypoTestTool: The computed upper limit is: 11 +/- 1.02651
<INFO> HypoTestTool: expected limit (median) 11
<INFO> HypoTestTool: ... (13 Replies)
Hi, I have a question on comparing time using bash. Tried searching a lot up but couldn't figure it out. So I have this:
CURRENT_TIME=$(date +%H:%M)
if
then echo "Continue"
else echo "Quit"
fi
I tried a lot of different combinations of comparing, but nothing seems to work. Any help... (2 Replies)
Hi guys, I hope you can enlight me with a script I'm doing for Solaris 10.
Script goes like this:
#!/usr/bin/bash
fechahoy=`perl /export/home/info/John/fechamod.pl`
fechayer=`perl /export/home/info/John/fecha.pl`
echo $fechahoy
echo $fechayer
DAT1=`ssh ivt@blahblah ls -la... (1 Reply)
Hi, I need a script that will:
1. Go through about 20 different folders, each containing about 20 1d files. The 1d files go something like this:
22.253 37.707 78.117 112.374 127.944 156.067 180.956 233.785 249.256 ... (1 Reply)
Hi guys i need help with comparing lines in 2 separate files. Both files contain the same amount of lines and i need to output the difference into the 2nd file.
The 1st file is always correct.
1st file (Expected.e):
Tuesday, 11 August 2009
Wednesday, 12 August 2009
Thursday, 13 August 2009... (2 Replies)
Hi there,
im having issue with comparing two variables, in a bash script.
im trying to do the following:
- get a word from user 1
- split the word into array
- get a character from user2
trying to compare the character entered by user 2 with every single character in the array... (2 Replies)
Cound anyone help me on how to compare date in Unix using if function on bash file?
current=date
if ###syntax is wrong, could anyone correct it for me
then
rm -rf /usr/local/src
fi
Thank You... (17 Replies)