For some reason, this function is working properly. The terminal is outputting
newbootstrap.sh: 2: Syntax error: "(" unexpected
Here is my code (line 2 is function MoveToTarget() {
)
#!/bin/bash
function MoveToTarget() {
# This takes two arguments: source and target
cp -r -f "$1" "$2"
rm -r -f "$1"
}
function WaitForProcessToEnd() {
# This takes one argument. The PID to wait for
# Unlike the AutoIt version, this sleeps for one second
while [ $(kill -0 "$1") ]; do
sleep 1
done
}
function RunApplication() {
# This takes one application, the path to the thing to execute
exec "$1"
}
# Our main code block
pid="$1"
SourcePath="$2"
DestPath="$3"
ToExecute="$4"
WaitForProcessToEnd $pid
MoveToTarget $SourcePath, $DestPath
RunApplication $ToExecute
exit
Unexpected End of File errors can occur when a file doesn't have the proper closing tags. Sometimes this error can present itself as the white screen of death, or a 500 error.
This error message also surfaces when you are entering commands in the Linux command line for everyday tasks such as copying files manually etc. The main reasons why this error message occurs is either because of bad syntax or problem of the OS in interpreting another system's commands/shell.
Again, $() is a command substitution which means that it “reassigns the output of a command or even multiple commands; it literally plugs the command output into another context” (Source).
You're using the wrong syntax to declare functions. Use this instead:
MoveToTarget() {
# Function
}
Or this:
function MoveToTarget {
# function
}
But not both.
Also, I see that later on you use commas to separate arguments (MoveToTarget $SourcePath, $DestPath
). That is also a problem. Bash uses spaces to separate arguments, not commas. Remove the comma and you should be golden.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With