Skip to main content
Added standard terminology; added (restored) a question to the question body; changed tags.
Source Link

I want to assign the result of an expression to (i.e., the output from a command) to a variable and concatenatethen manipulate it – for example, concatenate it with a string, then echo it. Here's  Here's what I've got:

#!/bin/bash
cd ~/Desktop;
thefile= ls -t -U | grep -m 1 "Screen Shot";
echo "Most recent screenshot is: "$thefile;

But that outputs:

Screen Shot 2011-07-03 at 1.55.43 PM.png
Most recent screenshot is: 

So, it looks like that isn't getting assigned to $thefile, and is being printed as it's executed.

What am I missing?

I want to assign the result of an expression to a variable and concatenate it with a string, then echo it. Here's what I've got:

#!/bin/bash
cd ~/Desktop;
thefile= ls -t -U | grep -m 1 "Screen Shot";
echo "Most recent screenshot is: "$thefile;

But that outputs:

Screen Shot 2011-07-03 at 1.55.43 PM.png
Most recent screenshot is: 

So, it looks like that isn't getting assigned to $thefile, and is being printed as it's executed.

I want to assign the result of an expression (i.e., the output from a command) to a variable and then manipulate it – for example, concatenate it with a string, then echo it.  Here's what I've got:

#!/bin/bash
cd ~/Desktop;
thefile= ls -t -U | grep -m 1 "Screen Shot";
echo "Most recent screenshot is: "$thefile;

But that outputs:

Screen Shot 2011-07-03 at 1.55.43 PM.png
Most recent screenshot is: 

So, it looks like that isn't getting assigned to $thefile, and is being printed as it's executed.

What am I missing?

Removed noise
Source Link
dr_
  • 32.4k
  • 22
  • 102
  • 148

I want to assign the result of an expression to a variable and concatenate it with a string, then echo it. Here's what I've got:

#!/bin/bash
cd ~/Desktop;
thefile= ls -t -U | grep -m 1 "Screen Shot";
echo "Most recent screenshot is: "$thefile;

But, that outputs:

Screen Shot 2011-07-03 at 1.55.43 PM.png
Most recent screenshot is: 

So, it looks like that isn't getting assigned to $thefile$thefile, and is being printed as it's executed.

I'm rather new to this; I'm sure I'm just missing something basic.

Thanks for your patience!

I want to assign the result of an expression to a variable and concatenate it with a string, then echo it. Here's what I've got:

#!/bin/bash
cd ~/Desktop;
thefile= ls -t -U | grep -m 1 "Screen Shot";
echo "Most recent screenshot is: "$thefile;

But, that outputs:

Screen Shot 2011-07-03 at 1.55.43 PM.png
Most recent screenshot is: 

So, it looks like that isn't getting assigned to $thefile, and is being printed as it's executed.

I'm rather new to this; I'm sure I'm just missing something basic.

Thanks for your patience!

I want to assign the result of an expression to a variable and concatenate it with a string, then echo it. Here's what I've got:

#!/bin/bash
cd ~/Desktop;
thefile= ls -t -U | grep -m 1 "Screen Shot";
echo "Most recent screenshot is: "$thefile;

But that outputs:

Screen Shot 2011-07-03 at 1.55.43 PM.png
Most recent screenshot is: 

So, it looks like that isn't getting assigned to $thefile, and is being printed as it's executed.

edited title
Link
peterph
  • 31.5k
  • 3
  • 74
  • 76

How can I assign the resultoutput of a command to a shell variable?

edited title
Link
terdon
  • 252.7k
  • 69
  • 481
  • 719
Loading
added 3 characters in body
Source Link
Nathan G.
  • 1.4k
  • 2
  • 10
  • 8
Loading
Tweeted twitter.com/#!/StackUnix/status/87679090722734080
edited tags
Link
Gilles 'SO- stop being evil'
  • 866.1k
  • 205
  • 1.8k
  • 2.3k
Loading
Source Link
Nathan G.
  • 1.4k
  • 2
  • 10
  • 8
Loading