Shell – how to split the string after and before the space in shell script

shellstring

I am having a variable which shows on echo like this

$ echo $var
129 148

I have to take only 129 as output.
How will I split 129 and 148?

Best Answer

In addition to jasonwryan's suggestion, you can use cut:

echo $var | cut -d' ' -f1

The above cuts the echo output with a space delimiter (-d ' ') and outputs the first field (-f1)

Related Question