To save the result of a command you can use the var=$(command)
expression.
In your case,
last_dir=$(ls -tr ParentFolder | tail -1)
So then you can cp $last_dir /another/path
, etc.
Note by the way that parsing ls
is not very optimal, so if you know that the dir name will always have today's date, you can get it with the date
command:
$ date
Thu Oct 3 11:02:28 CEST 2013
And its options:
$ date "+%Y-%m-%dT%H%M%z"
2013-10-03T1108+0200