0

I try to echo the result of a command. But my problem is that the result has strange values at the end and I can not delete them.

My result after the command is for example:

fnRead 

results to 12. Juni 13:32:18 2028 þ§

But I only need 12. Juni 13:32:18 2028 because I want to check the equivalence of two strings

My code that generates this output is a function:

fnRead() {
    echo $(cat /dev/rtc)
}

I tried to cut off the last strings but it will only remove numbers from the year.

Im working with shell scripts by the way.

4
  • Note that simply cat /dev/rtc would do the job; there's no need for the command substitution and echo. Commented Jul 21, 2015 at 14:14
  • sry forgot to mention that the cat /dev/rtc is inside a function. I use $(cat /dev/rtc) to execute the command and getting the result als an echo Commented Jul 21, 2015 at 14:19
  • OK; working out context can be tricky. It's not unreasonable to need var=$(cat /dev/rtc) — or, in Bash, var=$(</dev/rtc) — to assign to a variable for later use and then echo for debugging/checking purposes. Separately, haven't they fixed things like this by the year 2028? I was hoping things would have improved by then. And thank you for dropping back to chat with us. Does this mean that SO doesn't exist still in 2028? Commented Jul 21, 2015 at 14:21
  • Very funny ;) I can rewrite this date. This was only an example for my format of date. I am writing tests in shell script. Therefore it is important to know which date was written into the chip Commented Jul 21, 2015 at 14:28

1 Answer 1

2

According to documentation, you need to use hwclock to read/write from /dev/rtc. You are seeing a raw output of this interface.

See also: http://linux.die.net/man/4/rtc

Sign up to request clarification or add additional context in comments.

3 Comments

there are several ways to get the time. I need to use both commands. hwclock which uses ioctl and cat /dev/rtc which uses rtc_read function. This is because I wrote my own rtc driver.
Are you sure your RTC driver is doing what it is supposed to do?
Yes ;) Its for educational purpose only. I have to set a range of years which the chip can handle. So its possible for me to write time in the future

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.