a=Hello-World
b=$(a|cut -d- -f1)
echo "$b"
The above commands are not working for me. Any input?
a=Hello-World
b=$(a|cut -d- -f1)
echo "$b"
The above commands are not working for me. Any input?
a=Hello-World
b=$(echo $a|cut -d- -f1)
echo "$b"
Why do people always ask such very easy questions? RTFM can resolve most of these questions. Learn by yourself first please.
echo
for arbitrary data, cut
works on each line of its input not on its input as a whole, command substitution strips trailing newline characters. Would be better as b=${a%%-*}
here.
– Stéphane Chazelas
Nov 14 '17 at 09:06