0

I am writing a shell script that reads and reports out timestamps (the current timestamp is stored in $g2). Eventually I will be comparing the two timestamps.

I want to check if $t2 is empty - if it is, the store it as $g2. If not, then to replace $t2 as $t1, and store the new $g2 value as $t2.

I am trying to output this in a sudo csv style file - but when I attempt to run this script I keep getting command not found errors. Any suggestions?

if
    [[ -z "$t2" ]]
then
    $t2=$g2
    echo "$t1,0,0" >> just_time.txt
else
    $t2=$t1
    $t2=$g2
    echo "$t2,$t1,0" >> just_time.txt
fi
2
  • 1
    $t2 = replaced by the value of t2. So you want t2=$g2 and not $t2=$g2. Commented Dec 16, 2013 at 9:43
  • Thanks for this - but it still doesn't work. Commented Dec 16, 2013 at 9:51

1 Answer 1

1

Try this :

if
    [[ -z "$t2" ]]
then
    t2=$g2
    echo "$t1,0,0" >> just_time.txt
else
    t1=$t2
    t2=$g2
    echo "$t2,$t1,0" >> just_time.txt
fi
Sign up to request clarification or add additional context in comments.

2 Comments

That has only just printed a single timestamp on each line.
Can you post your whole shell script and the error you are getting?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.