I execute the program using the program name at the prompt 'roger_eod_ofac.cfg' also by preceding the program name with a period '. roger_eod_ofac.cfg'.
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:
[[ $currentfiledate -gt $reportfiledate ]]
Or better use the (( )) compound command:
(( "$currentfiledate" > "$reportfiledate" ))
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?
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:
$ var="a b"
$ [ $var = "a b" ]
bash: [: too many arguments
-- pathname expansion:
$ touch x
$ var=\*
$ set -x
$ [ $var = "*" ]
+ '[' x = '*' ']'
particular syntax for logical comparison:
$ [ value = value -a 1 -lt 2 ]&&echo true
true
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:
$ unset var
$ set -x
$ [[ $var -eq value ]]
+ [[ '' -eq value ]]
$ var=a\ b
$ set -x
[[ $var == "a b" ]]
+ [[ a b == \a\ \b ]]
new versions of bash support new operators:
$ var=abc
[[ $var =~ ^a ]]&&echo OK
OK
$ echo "${BASH_REMATCH[@]}"
a
readable operators for logical comparison:
$ [[ value == value && 2 < 1 ]]||echo false
false
The compound command ((expression)). From the manual pages for bash[3]:
$ unset a
$ ((++a))&&echo $a # version >= 3
1
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: