Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

This is the code:

#!/bin/bash
$REPORT_PATH='/data/operational/logs'
cp "$(`ls -t | head -1`)" "$REPORT_PATH/new_file"

This gives error 'cp:cannot access pda_param'.

pda_param file is o/p of ls command.

But this command works when I run it from logs directory. I have also granted full permission to logs directory.

Any ideas?

share|improve this question
1  
Remove $ (in second line) when you assign a string/value to variable. –  Cyrus Mar 7 at 17:21
2  
$() and and `` are the same. Just use "$(ls -t | head -1)" –  ott-- Mar 7 at 17:37
    
Yes, I have removed ``. Still getting error. The command runs from logs folder though as before. –  Menon Mar 9 at 13:51
    
Can you update the question (remove backtics) and explain in what directory it doesn't work? When it works in the logs dir, then the pda_param file should also be in the logs dir. Or did you simplify the question and removed some variables? –  Walter A Mar 10 at 21:58
    
Thanks for replies,guys. I got it. –  Menon Mar 16 at 9:43

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.