Skip to content
Advertisement

I am unable to type cast string to integer in csh

I want to fetch out ‘-0.5’ from the file example.txt and add 1 to it.

Although I am able to fetch out ‘-0.5’. but I am unable to add 1 to it, maybe because -0.5 is considered as a string and not a integer.

Code:

JavaScript

Obtained Result:

JavaScript

Expected Result:

JavaScript

How do I type cast -0.5 to integer?

Advertisement

Answer

csh doesn’t have types, and everything is a string.

The problem is that expr only accepts integers: that is, whole numbers. The same applies to csh’s built-in @ syntax.

It’s usually better to use bc or dc for this:

JavaScript

So in your example:

JavaScript
Advertisement