-6

This question already has an answer here:

a=Hello-World
b=$(a|cut -d- -f1)
echo "$b"

The above commands are not working for me. Any input?

marked as duplicate by αғsнιη, Jeff Schaller, peterh, Stephen Rauch, Romeo Ninov Nov 14 '17 at 15:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

-1
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.

  • 2
    You forgot the quotes, you can't use 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 9:06
  • I know every detail(or knowledge) you mentioned. What I write here is in regard to the specific question. – Bruce Nov 14 '17 at 9:16
  • 2
    Why do people use echo or forget to quote their variables when they know it's wrong and bad practice? – Stéphane Chazelas Nov 14 '17 at 9:26
  • Ouch. Just ouch. – B Layer Nov 14 '17 at 10:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.