Operating System - HP-UX
1753519 Members
6078 Online
108795 Solutions
New Discussion юеВ

syntax for varaiable with spaces

 
SOLVED
Go to solution
Michael Allmer
Frequent Advisor

syntax for varaiable with spaces

I have found many threads that talk about spaces in file name and directories. I though that I was following the information in them but I am sptill having issues, and I must have sothing wrong in my syntax.
Script is as follows;
#!/usr/bin/sh
#
COPY_CMD=`rsync -avz`
#
LIST=`cat /home/allmerms/office_move/raid_mdb.txt`
#
DEST="/office"
#
#
for l in $LIST
do
$COPY_CMD "${l}" $DEST
done
17 REPLIES 17
James R. Ferguson
Acclaimed Contributor
Solution

Re: syntax for varaiable with spaces

Hi Mike:

# COPY_CMD=`rsync -avz`

...should be:

# COPY_CMD="rsync -avz"

Regards!

...JRF...
Michael Allmer
Frequent Advisor

Re: syntax for varaiable with spaces

Here is the example of the error that I am seeing;
+ /raid/documents/actuation/eng_pdu/Tony /office
./test_copy.sh[13]: /raid/documents/actuation/eng_pdu/Tony: not found.
+ Li/saved/MoveNewDesktop/work/PNcrossReference.mdb /office
./test_copy.sh[13]: Li/saved/MoveNewDesktop/work/PNcrossReference.mdb: not found.



The full path is;
"/raid/documents/actuation/eng_pdu/Tony Li/saved/work/PNcrossReference.mdb"
Steven Schweda
Honored Contributor

Re: syntax for varaiable with spaces

> [...] but I am sptill having issues [...]

Are those anything like _problems_? And do
we need to guess what they were, or might you
be persuaded to tell us?

> LIST=`cat /home/allmerms/office_move/raid_mdb.txt`

You have a file named "cat"?
James R. Ferguson
Acclaimed Contributor

Re: syntax for varaiable with spaces

Hi (again) Mike:

By the way, the use of backticks is deprecated in favor of '$()' as:

# LIST=`cat /home/allmerms/office_move/raid_mdb.txt`

...is better written:

# LIST=$(cat /home/allmerms/office_move/raid_mdb.txt)

...which, is more _efficiently_ done as:

# LIST=$(< /home/allmerms/office_move/raid_mdb.txt)

...which causes the shell to perform the read of the file without forking a separate process (here, 'cat').

Regards!

...JRF...
Michael Allmer
Frequent Advisor

Re: syntax for varaiable with spaces

Thanks James, you help was what I needed.
Michael Allmer
Frequent Advisor

Re: syntax for varaiable with spaces

After changing script to follwo James' suggestions:
#!/usr/bin/sh
#
COPY_CMD="rsync -avz"
#
LIST=$(#
DEST="/office"
#
#
for l in $LIST
do
$COPY_CMD "${l}" $DEST
done

I am still getting the following error form the output:

sent 29 bytes received 20 bytes 98.00 bytes/sec
total size is 0 speedup is 0.00
rsync error: some files could not be transferred (code 23) at main.c(892) [sender=2.6.8]
+ rsync -avz /raid/documents/actuation/eng_pdu/Tony /office
building file list ... rsync: link_stat "/raid/documents/actuation/eng_pdu/Tony" failed: No such file or directory (2)
done

sent 29 bytes received 20 bytes 98.00 bytes/sec
total size is 0 speedup is 0.00
rsync error: some files could not be transferred (code 23) at main.c(892) [sender=2.6.8]
+ rsync -avz Li/saved/move/Program /office
building file list ... rsync: link_stat "/home/allmerms/office_move/Li/saved/move/Program" failed: No such file or directory (2)
done


In additions some of the file that where succesful are not what I expected. I wanted the full path created after /office
Exapmle:
"/raid/unigraphics/utils/var/tables/Teamcenter-DB.mdb"
Was created in /office as; /office/Teamcenter-DB.mdb

I was expecting;
"/office/raid/unigraphics/utils/var/tables/Teamcenter-DB.mdb"

I hope that I have explained my expectation correctly.
James R. Ferguson
Acclaimed Contributor

Re: syntax for varaiable with spaces

Hi (again) Mike:

A failed stat() means that the file or directory isn't found (or readable). See if this helps you:

...
for l in ${LIST}
do
[ -f "${l}" ] || { echo "missing file: ${l}"; continue; }
DIR=$(dirname ${l})
echo ${COPY_CMD} "${l}" "${DEST}${DIR}"
done

Regards!

...JRF...
Michael Allmer
Frequent Advisor

Re: syntax for varaiable with spaces

James,

Here is a log of the output from you latest suggested change.
James R. Ferguson
Acclaimed Contributor

Re: syntax for varaiable with spaces

Hi Mike:

> Here is a log of the output from you latest suggested change.

Without seeing what the input file for that run looks like, it is difficult to comment.

Regards!

...JRF...