0

Hi but it appears that if my strings have spaces in it, it won't work properly. My entire script is here:

#!/bin/bash  
echo $#; echo $@
MoveToTarget() {
    #This takes to 2 arguments: source and target
        echo ""$1"  "$2""
    cp -rf "$1"/* "$2"
    rm -r "$1"
}

WaitForProcessToEnd() {
    #This takes 1 argument. The PID to wait for
    #Unlike the AutoIt version, this sleeps 1 second
    while [ $(kill -0 "$1") ]; do
            sleep 1
    done
}

RunApplication() {
    #This takes 1 application, the path to the thing to execute
    open "$1"
}

#our main code block
pid="$1"
SourcePath="$2"
DestPath="$3"
ToExecute="$4"
WaitForProcessToEnd $pid
MoveToTarget "$SourcePath" "$DestPath"
RunApplication "$ToExecute"
exit

Note that I have tried the variables like $DestPath with and without quotes around them, with no luck. This code gets run with a Python script, and when the arguments are passed, quotes are around them. I appreciate any help!

Edit: (Python script)

bootstrapper_command = r'"%s" "%s" "%s" "%s" "%s"' % (bootstrapper_path, os.getpid(), extracted_path, self.app_path, self.postexecute)
shell = True
subprocess.Popen(bootstrapper_command, shell=shell)
9
  • Could you show the Python script? Commented Jun 14, 2011 at 21:06
  • 3
    a general debug tip, run it using #!/bin/bash -x then every variable with it's value is echoed to stdout as the script executes. Commented Jun 14, 2011 at 21:14
  • Could you echo $#; echo $@ at the top of the script? That might shed a little light. Commented Jun 14, 2011 at 21:17
  • "when the arguments are passed, quotes are around them" is wrong. Commented Jun 14, 2011 at 21:27
  • @Sorpigal I looked up on how to do it, I don't see the green arrow below my questions. Is it because I haven't registered? Commented Jun 14, 2011 at 21:39

2 Answers 2

2

Bash quotes are syntactic, not literal. Greg's Wiki, as usual, has the most excellent explanation you could wish for.

Sign up to request clarification or add additional context in comments.

1 Comment

Very useful info there. I'd +1 Greg too if I could
0

Try removing the *, it isn't needed for recursive copy.

cp -rf "$1"/* "$2"

to:

cp -rf "$1/" "$2"

I think globbing was ruining your quoting that was protecting you from spaces in filenames.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.