1

The shell variable number contains 1 1 1 1 1 separated by tabs.

I want it to contain only the first 1.

I'm trying

number= $(echo "$number"| cut -f 3 )

and I get the error "1: command not found" and the contents of number don't change.

What am I doing wrong?

Anthon
  • 79,293
Rio
  • 41

2 Answers2

5

Assuming that number is tab-separated, then consider:

number= $(echo "$number"| cut -f 3 )

The result of echo "$number"| cut -f 3 is the third element of numbers which is 1. Thus, the shell tries to execute:

number= 1

In this command, the variable number is temporarily set to empty and the shell tries to execute the command 1. Because there is no command named 1, the shell emits the error message:

bash: 1: command not found

This is the shell's attempt to tell you that it could find no command named 1.

The solution is to remove the space:

number=$(echo "$number"| cut -f 3 )

After command substitution, this becomes:

number=1

This will succeed at assigning number to have the value 1.

John1024
  • 74,655
2

Try without space after "=" sign. I mean, try

number=$(echo "$number"| cut -f 3 )

instead of

number= $(echo "$number"| cut -f 3 )