PDA

View Full Version : Linux Bash Script



chris_y2k_r1
31st January 2007, 04:30 PM
I have a couple of questions about bash scripting. I hope I've posed this in the right forum...

Anyway, I need to find a command that will extract the integer value of a numeric variable. For example, let's say the following:

let x=4.5
echo int(x)

Where int would be the integer value of x, if int was the actual command, then output would be 4.

Does anyone know what this command is called....

Also, totally unrelated, if I do a "yum update" on a fedora core 4 setup, does that mean I download most of the latest releases of packages? In other words, does that make my Fedora Core 4 installation closer to a Fedore Core 5 or 6....???

urzasrage
31st January 2007, 04:49 PM
Also, totally unrelated, if I do a "yum update" on a fedora core 4 setup, does that mean I download most of the latest releases of packages? In other words, does that make my Fedora Core 4 installation closer to a Fedore Core 5 or 6....???
Not really, just updates the programs on FC4 plus the kernel.

pianoplayer
31st January 2007, 07:22 PM
I have a couple of questions about bash scripting. I hope I've posed this in the right forum...

Anyway, I need to find a command that will extract the integer value of a numeric variable. For example, let's say the following:

let x=4.5
echo int(x)



I am not aware of an "int" function in bash, but here are two ways to get what you want. I am assuming that you have already created a variable called x which is the number for which you want the integer part.

Method 1:

echo $x | sed 's/\..*//'

Method 2:

echo $x | awk '{print int($1)}'

chris_y2k_r1
31st January 2007, 07:31 PM
Not really, just updates the programs on FC4 plus the kernel.

Ok - More specifically what's the difference? Is the Kernel and it's associated programs completely different?

pianoplayer
31st January 2007, 07:53 PM
sed and awk are utilities that date back to the early days of Unix. sed is a version of the original Unix editor ed, adapted to batch processing. awk is a programming language, suitable for one-line applications or for much larger applications. Many guides to bash programming give some introduction to these utilities; there are books available on awk.
(A very good one is Arnold Robbins, Effective Awk Programming.)

chris_y2k_r1
31st January 2007, 08:16 PM
I have the book, "Sed and Awk" where there is a drawing of two cute fuzy animals on the front, one being said and the other... Anyway, I need to read it because I see how power the functionality of these is.

Thanks PP!

RupertPupkin
1st February 2007, 04:49 AM
Anyway, I need to find a command that will extract the integer value of a numeric variable. For example, let's say the following:

let x=4.5
echo int(x)

Where int would be the integer value of x, if int was the actual command, then output would be 4.

x=4.5
echo "${x%.*}"
No need for sed or awk.