Basic bash scripting

rvcw
rvcw used Ask the Experts™
on
Getting into the basics of bash scripting, one thing I'm looking at is numerical comparisons.

I have the following code:

#!/bin/sh

current=`cat /root/VERSION.OLD`
new=`cat /root/VERSION`



if [["$current" -lt "$new"]]; then
echo "current is less than new"
echo "current is " $current
echo "new is " $new


else
echo "current is newer than new"
echo "current is " $current
echo "new is " $new
fi

Output is:

[root@dev ~]# sh rvtest
rvtest: line 8: [[201212241235: command not found
current is newer than new
current is  201212241235
new is  201212241236

Why the error? It's also not doing the comparison.

Line 8 is: if [["$current" -lt "$new"]]; then
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2014
Top Expert 2015
Commented:
if [["$current" -lt "$new"]]; then
should be
if [[ "$current" -lt "$new" ]]; then
As Ozo said, there should be spaces before ]] and after [[.

With [[ ]] you should use < instead of -lt in the Borne style.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial