4

Is there a way to assign a value to a variable, that value which we get in terminal by writing any command?

I try with this code:

!number_of_lines=$(wc -l < cord_19.json)
!echo $number_of_lines

I get empty output. When I run

!wc -l < cord_19.json

I get correct response with number.

Do you have idea what is wrong or how can I set variable?

CezarySzulc
  • 1,849
  • 1
  • 14
  • 30

1 Answers1

4

Try:

number_of_lines = !wc -l < cord_19.json
!echo $number_of_lines

or:

number_of_lines = !wc -l < cord_19.json
print(number_of_lines)

See Pipe Ipython magic output to a variable? for related discussion.

Marek Grzenkowicz
  • 17,024
  • 9
  • 81
  • 111