Solved

Basic bash scripting

Posted on 2012-12-24
2
184 Views
Last Modified: 2013-01-26
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
0
Comment
Question by:rvcw
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
ID: 38719406
if [["$current" -lt "$new"]]; then
should be
if [[ "$current" -lt "$new" ]]; then
0
 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 250 total points
ID: 38719446
As Ozo said, there should be spaces before ]] and after [[.

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

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
su - oracle could not open session 6 73
linux(debian) mouse poor performance 4 39
winscp where are logs stored 3 34
CENTOS DHCP Server / PXE/TFTP 14 74
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question