- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- syntax for varaiable with spaces
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 06:07 AM
07-22-2009 06:07 AM
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
Solved! Go to Solution.
- Tags:
- quoting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 06:19 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 06:22 AM
07-22-2009 06:22 AM
Re: syntax for varaiable with spaces
+ /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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 06:23 AM
07-22-2009 06:23 AM
Re: syntax for varaiable with spaces
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"?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 06:23 AM
07-22-2009 06:23 AM
Re: syntax for varaiable with spaces
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...
- Tags:
- command substitution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 06:24 AM
07-22-2009 06:24 AM
Re: syntax for varaiable with spaces
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 06:37 AM
07-22-2009 06:37 AM
Re: syntax for varaiable with spaces
#!/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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 07:18 AM
07-22-2009 07:18 AM
Re: syntax for varaiable with spaces
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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 07:35 AM
07-22-2009 07:35 AM
Re: syntax for varaiable with spaces
Here is a log of the output from you latest suggested change.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 08:29 AM
07-22-2009 08:29 AM
Re: syntax for varaiable with spaces
> 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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 08:30 AM
07-22-2009 08:30 AM
Re: syntax for varaiable with spaces
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 08:33 AM
07-22-2009 08:33 AM
Re: syntax for varaiable with spaces
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 08:48 AM
07-22-2009 08:48 AM
Re: syntax for varaiable with spaces
/raid/cad/777-lowerlobe/200-lr/docs/All_Side_Guide_BOMs.mdb
/raid/unigraphics/utils/var/tables/Teamcenter-DB.mdb
/raid/documents/actuation/eng_pdu/Tony_Li/saved/MoveNewDesktop/work/PNcrossReference.mdb
/raid/documents/actuation/eng_pdu/Tony_Li/saved/move/Program Files/Visual Sizer/VisualSizer.mdb
/raid/documents/actuation/eng_pdu/Tony_Li/saved/move/Program Files/Visual Sizer/appdata.mdb
/raid/documents/actuation/eng_pdu/Tony_Li/saved/move/Program Files/Visual Sizer/datatemp.mdb
/raid/documents/actuation/eng_pdu/Tony_Li/saved/move/Program Files/speed/spud/tuts/mag10.mdb
/raid/documents/actuation/eng_pdu/Tony_Li/saved/work/PNcrossReference.mdb
/raid/documents/actuation/eng_pdu/Tony_Li/saved/workold/PNcrossReferenceCustomerPN-1.mdb
/raid/documents/actuation/eng_pdu/Tony_Li/saved/workold/PNcrossReferenceCustomerPN.mdb
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 09:12 AM
07-22-2009 09:12 AM
Re: syntax for varaiable with spaces
Oh, you have _spaces_ in your filenames. I should have guessed that from your original post. Seeing actual input avoids ambiguous communication.
#!/usr/bin/sh
COPY_CMD="rsync -avz"
LIST="/home/allmerms/office_move/raid_mdb.txt"
DEST="/office"
while read FILE
do
[ -f "${FILE}" ] || { echo "missing file: '${FILE}'"; continue; }
DIR=$(dirname "${FILE}")
echo ${COPY_CMD} "'${FILE}'" "'${DEST}${DIR}'"
done < ${LIST}
exit 0
This also avoids forking a process to construct a list in memory. Instead we let the shell read each line of the file for us.
I would suggest that you read the 'rsync' manpages to make sure that the 'rsync' syntax gives you what you want.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 10:01 AM
07-22-2009 10:01 AM
Re: syntax for varaiable with spaces
using the last iput file I provided, I ran the following.
#!/usr/bin/sh
#
LIST="/home/allmerms/office_move/raid_mdb.txt"
#
#
while read FILE
do
[ -f "${FILE}" ] || { echo "missing file: ${FILE}"; continue; }
DIR=$(dirname ${FILE})
echo "${DIR}"
done < ${LIST}
exit 0
The output file show that it is dropping everything in the path name after the first space.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 10:12 AM
07-22-2009 10:12 AM
Re: syntax for varaiable with spaces
> The output file show that it is dropping everything in the path name after the first space.
Yes, you dropped quotes. Compare:
...
while read FILE
do
#-> [ -f "${FILE}" ] || { echo "missing file: ${FILE}"; continue; }
DIR=$(dirname ${FILE})
echo "<<< ${DIR}"
DIR=$(dirname "${FILE}")
echo ">>> ${DIR}"
done < ${LIST}
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 10:18 AM
07-22-2009 10:18 AM
Re: syntax for varaiable with spaces
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 11:16 PM
07-22-2009 11:16 PM
Re: syntax for varaiable with spaces
#!/bin/nash
COPY_CMD="rsync -avz"
LIST=$(cat /home/allmerms/office_move/raid_mdb.txt)
DEST="/office"
IFS="
"
for i in $LIST; do
$COPY_CMD "${i}" $DEST
done
Best regards
Fredrik Eriksson