Reputation: 13
I have a -d option in a bash script but I dont what it does
cp -r ${version} ${version}tm
[ -d "latest-oi" ] rm latest-oi #line 35
[ -d "latest-tm" ] rm latest-tm #line 36
ln -sf "${version}" latest-oi
ln -sf "${version}tm" latest-tm
and when I execute the script I have this error message, I don't know why
./script.sh: line 35: [: missing `]'
./script.sh: line 36: [: missing `]'
I would like to know what -d means and what it does and why there is an error when the script is executed, Thanks
Upvotes: 0
Views: 935
Reputation: 22225
I don't see any -d
option to your bash, but to the command [
. See man test for this command. If you want to have two commands in the same line, you have use a command separator between them. Valid command separators are a newline, a ;
, a &&
or a ||
.
If you write a
[ -d "latest-oi" ] && rm latest-oi
it means that the rm
is executed if [
returns exit code zero. Another way to write it would be
test -d latest-oi && rm latest-oi
If you would use a ||
instead, the rm
would be executed whenever [
returns non-zero exit code.
Upvotes: 3