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

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

ctrl-alt-delor
  • 27,473
  • 9
  • 58
  • 102
  • https://unix.stackexchange.com/help/how-to-ask and https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html – ilkkachu Nov 14 '17 at 08:59
  • 3
    "Not working", what do you mean by that terribly tough support question? I.e. what do you expect to happen, and which doesn't seem to be the case? After you edit your question to clarify that, I'll consider removing my downvote – Pierre.Vriens Nov 14 '17 at 09:01
  • 2
    Please explain what you mean by not working. Add any error messages to the question. – ctrl-alt-delor Nov 14 '17 at 10:08

1 Answers1

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

Bruce
  • 1,181
  • 9
  • 12
  • 2
    You [forgot the quotes](/q/171346), you [can't use `echo` for arbitrary data](/q/65803), `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
  • I know every detail(or knowledge) you mentioned. What I write here is in regard to the specific question. – Bruce Nov 14 '17 at 09: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 09:26
  • Ouch. Just ouch. – B Layer Nov 14 '17 at 10:56