bourne script problem


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers bourne script problem
# 1  
Old 07-29-2012
bourne script problem

I've got an NTFS file system mounted on my Linux box, which means I can have multi-word directory names. I want to recurse through the directory structure copying stuff from /A to /B when it does not already exist on /B. Here is the chunk of code, and the output of a set -x run on that chunk of code. Anybody see what I am doing wrong?
Code:
                                HOLDPATH=`/bin/pwd`
                                echo "HOLDPATH=$HOLDPATH"
                                cd /A
                                echo `/bin/pwd`
#                               If it is a directory, we want to tar up the whole thing, not just 1 file
#                               but if we got to here, it should be a file
                                echo "About to copy $PATH5 to /B"
####                            /bin/tar clf - "$PATH5" |(cd /B; /bin/tar xvpf -)
                                echo " "
                                echo "HOLDPATH=$HOLDPATH"
#                               HERE is where we need to mess with the path
                                HOLDPATH1=`echo "$HOLDPATH" | /bin/sed -e 's/\//\"\/\"/g' | /bin/sed 's/$/\"/' | /bin/sed 's/\"//'`
                                echo "HOLDPATH1=$HOLDPATH1"
                                cd $HOLDPATH
                                cd $HOLDPATH1

Code:
++ /bin/pwd
+ HOLDPATH='/A/Backup of  GB stick/Removable Disk (I)'
+ echo 'HOLDPATH=/A/Backup of  GB stick/Removable Disk (I)'
+ cd /A
++ /bin/pwd
+ echo /A
+ echo 'About to copy Backup of GB stick/Removable Disk (I)/03-RSE-DS_DNS.iso to /B'
+ echo ' '
+ echo 'HOLDPATH=/A/Backup of  GB stick/Removable Disk (I)'
++ /bin/sed 's/\"//'
++ /bin/sed 's/$/\"/'
++ /bin/sed -e 's/\//\"\/\"/g'
++ echo '/A/Backup of  GB stick/Removable Disk (I)'
+ HOLDPATH1='/"A"/"Backup of  GB stick"/"Removable Disk (I)"'
+ echo 'HOLDPATH1=/"A"/"Backup of  GB stick"/"Removable Disk (I)"'
+ cd /A/Backup of GB stick/Removable Disk '(I)'
/scriptr: line 127: cd: /A/Backup: No such file or directory
+ cd '/"A"/"Backup' of GB 'stick"/"Removable' Disk '(I)"'
/scriptr: line 128: cd: /"A"/"Backup: No such file or directory

Moderator's Comments:
Mod Comment code tags please

Last edited by jim mcnamara; 07-30-2012 at 12:16 AM..
# 2  
Old 07-30-2012
I note that the initial setting of HOLDPATH contains two spaces between "of" and "BG", but the setting of PATH5 contains only one space there. This script doesn't show how PATH5 is set, but I'm guessing that something isn't appropriately quoted resulting in the loss of a space character in PATH5.

Instead of the complicated messing with HOLDPATH to produce HOLDPATH1 at the end of your script, I think you just want to use:
Code:
cd "$HOLDPATH"

instead of using the multiple calls to sed to insert double quote characters into HOLDPATH1 and using:
Code:
cd $HOLDPATH1

without the enclosing double quotes.
# 3  
Old 07-30-2012
Bournce script problem

That is a great pick up about the extra space. I wish I knew where it came from. The three lines below

Code:
                        echo `/bin/pwd`
                        HOLDPATH=`/bin/pwd`
                        echo "HOLDPATH=$HOLDPATH"

produced the following 5 lines of output

Code:
++ /bin/pwd
+ echo /A/Backup of GB stick/Removable Disk '(I)'
++ /bin/pwd
+ HOLDPATH='/A/Backup of  GB stick/Removable Disk (I)'
+ echo 'HOLDPATH=/A/Backup of  GB stick/Removable Disk (I)'

Any idea where that extra space came from?

Last edited by Scott; 07-30-2012 at 11:11 AM.. Reason: Code tags, please.
# 4  
Old 07-30-2012
It is part of the directory name. You lost the space with your echo because it was not quoted.

Code:
[mute@geek ~/temp/two spaces->  <-]$ echo `pwd`
/home/mute/temp/two spaces-> <-
[mute@geek ~/temp/two spaces->  <-]$ echo "`pwd`"
/home/mute/temp/two spaces->  <-

You may want to look into rsync. It will do local copies as well.
# 5  
Old 07-30-2012
As neutronscott points out, there is no extra space in $HOLDPATH; there is a missing space in $PATH5. Please show us all of the code that sets the value stored in $PATH5.

And, while you're at it, please change:
Code:
#                               HERE is where we need to mess with the path
                                HOLDPATH1=`echo "$HOLDPATH" | /bin/sed -e 's/\//\"\/\"/g' | /bin/sed 's/$/\"/' | /bin/sed 's/\"//'`
                                echo "HOLDPATH1=$HOLDPATH1"
                                cd $HOLDPATH
                                cd $HOLDPATH1

to:
Code:
                                cd "$HOLDPATH"

or explain why you need HOLDPATH1.
# 6  
Old 07-30-2012
Here's the script problem boiled down to two lines

Let's get it down to two lines

Code:
                PATH3=`/bin/pwd` > /dev/null
                PATH4=`echo $PATH3 | /bin/sed -e 's/\/A/\/B/'`

And the trace output is

Code:
++ /bin/pwd
+ PATH3='/A/Backup of  GB stick/Removable Disk (I)'
++ /bin/sed -e 's/\/A/\/B/'
++ echo /A/Backup of GB stick/Removable Disk '(I)'
+ PATH4='/B/Backup of GB stick/Removable Disk (I)'

The question is, how did the two spaces between of and GB get changed to one space?
Moderator's Comments:
Mod Comment Code tags for code, please.

Last edited by Corona688; 07-31-2012 at 11:19 AM..
# 7  
Old 07-30-2012
Quote EVERY expansion!! echo "$PATH3"
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bourne Shell - Problem with while loop variable scope.

Hello I am having issues with a script I'm working on developing on a Solaris machine. The script is intended to find out how many times a particular user (by given userid) has logged into the local system for more than one hour today. Here is my while loop: last $user | grep -v 'sshd'... (7 Replies)
Discussion started by: DaveRich
7 Replies

2. Shell Programming and Scripting

help with bourne shell script

Attempting to write a script to eventually notify me via email for when there is packetloss across the backbone. I am looking for values greater than 0% in the mtr field. #!/bin/sh target=www.google.com date +"%D"_"%T" >> /home/rich/mtr.log echo "----------------------------------------" >>... (1 Reply)
Discussion started by: closedown
1 Replies

3. Shell Programming and Scripting

help with bourne script

Hey guys not sure why but when i execute the script i get the correct result but then it says command not found not sure why can anyone see anything wrong with my code below? I just want to print how much quota i have used in my home directory #!bin/sh `quota -v | grep ^/home | awk... (2 Replies)
Discussion started by: musicmancanora4
2 Replies

4. Shell Programming and Scripting

if loop problem in bourne shell

how to use if-loop in bourne shell with multiple conditions like follows if then commands fi it gives me an error test: ] missing then i put if ] it gives me an error [[ not found kindly i need the syntex for the bourne shell (5 Replies)
Discussion started by: ahmad.diab
5 Replies

5. Shell Programming and Scripting

Sh, Bourne Problem with getting lines in a file

This is a new exercise for me 1.) Create a bourne shell script that can accept 2 arguments/parameters. Name your script as housekeep_files.sh. 2.) The script will delete the files specified in the input file (1st parameter) and will send a notification through email (2nd parameter) the... (1 Reply)
Discussion started by: kdyzsa
1 Replies

6. Shell Programming and Scripting

Bourne Script help

Hey guys, I am trying to do a bourne script to look for c files in the current directory. I had it working where it finds the files and asks you to delete them or not, which works, but if there i no files, then it comes up with errors, which iam trying to get rid of. So I thought I would do a if... (2 Replies)
Discussion started by: Pits
2 Replies

7. Shell Programming and Scripting

please give a bourne script to this problem

Hello all, I am new to unix and having the below problem.Any help will be appreciated. Write a Bourn shell script dTOe which takes as an input any number between 0 and 999 and prints the English value for this number. The program should display an error message when a NOT digit value entered.... (1 Reply)
Discussion started by: raj1811
1 Replies

8. Shell Programming and Scripting

bourne script help

I need to make a small script that figures out if a filename that the user enters is a file or a directory. and if it is a directory, how many files are in it. please point me to the right direction, I am a newbie at this. (1 Reply)
Discussion started by: Heedunk
1 Replies

9. Shell Programming and Scripting

simple Bourne problem

Hi, I'm a newer for this languages, and I have a log file, which is something like this: 35.75.253.207 - - "GET /products/orgonizer/title.png HTTP/1.1" 200 1555 "-" "Mozilla 1.4" Now, I want to write a shell code to accoplish like ./XXX.sh -N n n is a number by user input, the code should... (5 Replies)
Discussion started by: pnxi
5 Replies

10. Shell Programming and Scripting

bourne mail script problem

Hey there, Just have a quick question. i've written a program and it needs to send a email to confirm it's completed. now i've done the mail -s "Subject" test@test.com the problem is the program, when run just waits. it doesn't execute the next command unless i press ^D. is there away... (6 Replies)
Discussion started by: Priest_Ridden
6 Replies
Login or Register to Ask a Question