Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm not quite sure what the issue is. I'm on Kali Linux 2.0 right now, fresh install. The following worked on Ubuntu 14.04 but it's not working anymore (maybe I accidentally changed it?). It looks correct to me, but every time it runs it blocks.

backup_folder=$(ssh -i /home/dexter/.ssh/id_rsa $server 'ls -t '$dir' | head -1')

This is part of a larger script. $server and $dir are set. When I run the command alone, I get the correct output, but it doesn't end the connection.

share|improve this question
2  
just FYI, it works for me on Ubuntu 15.04. I also don't see anything wrong on the first sight. – Jakuje Oct 15 '15 at 21:36
    
You may want to quote the $dir expansion, lest you might run into problems if $dir ever expands to a path that contains whitespace or shell metacharacters. – Michael Kjörling Apr 15 '16 at 9:14

I have had the same issue recently, probably you should add a redirection to stdout at the end of the command, like so:

backup_folder=$(ssh -i /home/dexter/.ssh/id_rsa $server 'ls -t '$dir' | head -1' 2>&1)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.