-1

how can I get to echo and save as variable?

sm@tp1:~/pc$ php get.php | grep "PhP" | cut -c24-33 | sed -n 1p
PhP 47.813

this is the output

sm@tp1:~/pc$ out=$(php get.php | grep "PhP" | cut -c24-33 | sed -n 1p) | echo $out
sm@tp1:~/pc$

but in here there is no output

RedX
  • 14,749
  • 1
  • 53
  • 76
jmazaredo
  • 493
  • 1
  • 4
  • 9
  • Possible duplicate of [How to set a variable equal to the output from a command in Bash?](http://stackoverflow.com/questions/4651437/how-to-set-a-variable-equal-to-the-output-from-a-command-in-bash) – Benjamin W. Jan 26 '16 at 03:23

2 Answers2

2

In the second line you are assigning the output to the variable out. If you later want to see what the variable out is, just type echo $out afterwards:

sm@tp1:~/pc$ out=$(php get.php | grep "PhP" | cut -c24-33 | sed -n 1p)
sm@tp1:~/pc$ echo $out

In other words, don't use the pipe | and just echo on another line, or you can just replace that pipe with a semicolon ;.

sm@tp1:~/pc$ out=$(php get.php | grep "PhP" | cut -c24-33 | sed -n 1p); echo $out
e0k
  • 6,961
  • 2
  • 23
  • 30
1

Just to add , In this case

    out=$(php get.php | grep "PhP" | cut -c24-33 | sed -n 1p)|echo $out

Each of the command shall run in separate subshell where you can pipe stdout as stdin but passing variable is not possible. In your case variable is out

Varun
  • 447
  • 4
  • 9