Reputation:
I have this bash script:
#!/usr/bin/env bash
function onqltrap {
echo "process with pid $$ was trapped.";
fle=$(echo "$(pwd)" | tr "/" _);
rm -f fle;
}
function qltrap {
trap onqltrap EXIT;
}
function qlstart {
set -e;
trap onqltrap EXIT;
mkdir -p "$HOME/.quicklock/locks"
fle=$(echo "$(pwd)" | tr "/" _)
mkdir "$HOME/${fle}.lock" || { echo "quicklock could not acquire lock."; exit 1 }
}
function qlstartold {
mkdir -p "$HOME/.quicklock/fifo"
rm "$HOME/.quicklock/fifo/$$.fifo"
mkfifo "$HOME/.quicklock/fifo/$$.fifo"
}
when I source this file in a script, I get this error:
bash: /Users/alexamil/WebstormProjects/oresoftware/quicklock/quicklock-trap.sh: line 28: syntax error: unexpected end of file
does anyone know why that error is happening?
Upvotes: 0
Views: 711
Reputation: 241771
Using the helpful http://shellcheck.net as strongly recommended in the bash summary, I discovered:
Line 19:
mkdir "$HOME/${fle}.lock" || { echo "quicklock could not acquire lock."; exit 1 }
>> ^-- SC1083: This } is literal. Check expression (missing ;/\n?) or quote it.
(scroll to the right to see the error.)
In the original output, SC1083 is linked to https://github.com/koalaman/shellcheck/wiki/SC1083 which has more information on the error. What is possibly unclear from the write-up is that the fact that the } is being treated as a literal argument implies that it is not being treated as the end of the function definition; when the end of the script file is reached, that function is still open.
Upvotes: 2