-1

I am trying to put the output of a bash command (filename) into a string for later access.

echo "$(ls -Art | tail -n 1)"

successfully prints out the latest file updated in the directory (good).

The problem occurs when I try to store this into a var. to access later in the script.

Any suggestions on how to do so? I've seen different methods, but it didn't seem to work/ apply because I'm using the param -Art for ls.

Thanks!

further info: filename still gets kicked back as the {actual filename}: command not found

filename = `ls -Art | tail -n 1`
3
  • I assume you want something like this, in which case I don't see the problem unless you're using assignment incorrectly: $ x=$(ls -Art | tail -n 1) $ echo $x Commented Jan 1, 2016 at 22:19
  • 1
    shellcheck says "Don't put spaces around the = in assignments." Commented Jan 1, 2016 at 22:26
  • thanks! @thatotherguy Commented Jan 1, 2016 at 22:30

1 Answer 1

0

shellcheck says "Don't put spaces around the = in assignments." – that other guy 1 min ago

@that-other-guy was correct. It had to do with the spaces around the '='

Thanks!

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.