Reputation: 2673
I have to cut the string after the white-space and store the value before white-space. My example script is show below
tString="This is my name"
echo $tString | cut -d' ' -f1
output:
This
Now I want to assign this output value to the variable. My script is
tString="This is my name"
var=$($tString | cut -d' ' -f1)
It shows error.Error message is
This: command not found
Iam new to bash shell script. Anyone Knows how to do this.
Upvotes: 2
Views: 5808
Reputation: 4554
Using parameter expansion:
tString="This is my name"
var="${tString%% *}"
echo "$var"
This
Upvotes: 1