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.

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 have created a small script to move video files from a helmet mounted camera to my mythbuntu machine and there is a variable that for some reason will just not be passed onto the script. The variable in question is

d=`echo $file | awk '{ print $6 }'`

which is captured OK, however in the statement

scp -l 5000 $name $SavePath$d_$hour.AVI

will just not insert a value.

# This script does copy files from /media/disk/DCIM/100DSCIM to 
# and renames the files using the time stamp
set -x
ls $SourcePath*.AVI --full-time > file_list
cat file_list | while read file
    d=`echo $file | awk '{ print $6 }'`
    hour=`echo $file | awk '{ print $7 }'`
    name=`echo $file | awk '{ print $9 }'`
    scp -l 5000 $name $SavePath$d_$hour.AVI
share|improve this question

This is because bash interprets variable name as d_. Use curly braces to border variable name in that case:

scp -l 5000 $name $SavePath${d}_$hour.AVI

or even

scp -l 5000 ${name} ${SavePath}${d}_${hour}.AVI

and it's much better to double quote variable to prevent error with name with strange symbols like space:

scp -l 5000 "${name}" "${SavePath}${d}_${hour}.AVI"
share|improve this answer
This answer is exactly right. But I wish I had a nickel for every time I've seen scripts using ${...} where it wasn't needed, most often in the apparent belief that ${foo} worked like "$foo". – dubiousjim Oct 19 '12 at 14:30
Thanks very much, that has worked perfectly OK – Inspector Gadget Oct 20 '12 at 21:30

Your Answer


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.