Author: Victor Churchill Date: To: stephen.davies, Hampshire LUG Discussion List CC: Subject: Re: [Hampshire] Handling Volume Labels with Spaces
On 15/02/2008, Stephen Davies <stephen.davies@???> wrote: > The problem lies in that most of the input media ( The CF Cards ) have
> volume labels built in which cannot be changed and these labels contain
> space characters.
> When the O/S detects a CF card being inserted, it mounts it as
> /media/'volume label'
>
> for example (from the output of a df command )
> /dev/sdc1 /media/Test Volume
>
> I can get the volume string using the following
>
> cat /proc/mounts | grep sdc1 | awk '{ print $2 }'
>
> This gives "Test\40Volume"
> However this is unusable in commands a the space is translated to "\40"
>
> eg
> involume=`cat /proc/mounts | grep sdc1 | awk '{ print $2 }'`
> cp -R $involume ${outvol1}/${copy_date}/.
>
> ( $outvol1 & $copy_date are setup elsewhere in the script )
> The format of $involume is invalid and an error is reported.
>
> Any thoughts on how to make this work would be most welcome.
> Does quoting help?
victor@ss07:~/Desktop$ [1] DIRNAME="A Test"
victor@ss07:~/Desktop$ [1] echo $DIRNAME
A Test
victor@ss07:~/Desktop$ [1] touch !$/foo
touch "A Test"/foo
victor@ss07:~/Desktop$ [1] mkdir "A Test"/"A subfolder"
victor@ss07:~/Desktop$ [1] touch !$/foo2
touch "A Test"/"A subfolder"/foo2
Not sure if that would cope with the \040 that you mention though. I
suspect if you can get the label un-escaped you should be able to get
away with it.