0

I forked https://github.com/mathiasbynens/dotfiles dotfiles and tried to run bootstrap.sh which apparently should "pull in the latest version and copy the files to your home folder", according to the README.md

But when I try to source the bootstrap.sh, error returns. "bootstrap.sh:13 := not found". Line 13 is the doIt part in

if [ "$1" == "--force" -o "$1" == "-f" ]; then doIt;

Does anybody have an idea where it went wrong? Thanks in advance.

#!/usr/bin/env bash

cd "$(dirname "${BASH_SOURCE}")";

git pull origin master;

function doIt() {
    rsync --exclude ".git/" --exclude ".DS_Store" --exclude ".osx" \
    --exclude "bootstrap.sh" --exclude "README.md" --exclude "LICENSE-MIT.txt" -avh --no-perms . ~;
    source ~/.bash_profile;
}

if [ "$1" == "--force" -o "$1" == "-f" ]; then
    doIt;
else
    read -p "This may overwrite existing files in your home directory. Are you sure? (y/n) " -n 1;
    echo "";
    if [[ $REPLY =~ ^[Yy]$ ]]; then
        doIt;
    fi;
fi;
unset doIt;
Bossam
  • 744
  • 2
  • 9
  • 24
  • 2
    How are you running it? – melpomene Jul 31 '16 at 09:43
  • There's a lot in here that's poorly-written -- the author clearly made no effort to use POSIX sh compliant practices even when there's absolutely no (syntax, semantic, or readability) advantage to bashisms. I'd tend to be a bit skeptical about using this script. – Charles Duffy Jul 31 '16 at 13:15
  • ...and, actually, that's part of the problem: This script was written specifically for bash, the shell you're using isn't bash. – Charles Duffy Jul 31 '16 at 13:16
  • 1
    ...so, let's start with some examples: `[ "$1" == "force" -o "$1" == "-f" ]` -- see the POSIX `test` spec at http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html. First, `==` isn't a supported operator; string comparisons should use `=`. Second, `-o` is marked "OB", obsolescent; that shouldn't be used either; instead, it should be `[ "$1" = --force ] || [ "$1" = -f ]`, **if** one were targeting all POSIX shells. – Charles Duffy Jul 31 '16 at 13:17
  • "source the bootstrap.sh" -- how? Are you running `sh bootstrap.sh`? `source bootstrap.sh`? Something else? – Charles Duffy Jul 31 '16 at 13:27

1 Answers1

1

It seems your shell has a problem with the == in the [ command. The thing is, this operator is undocumented for this old command, so it's possible that some shells won't like it.

The command should work in a modern Bash, for example if you run the script this way:

bash bootstrap.sh

or this way:

./bootstrap.sh

Ideally, the script should not use obscure syntax, for example use this instead:

if [[ $1 == --force || $1 == -f ]]; then
janos
  • 120,954
  • 29
  • 226
  • 236
  • ...or `case $1 in --force|-f) ...`, as a POSIX alternative. – Charles Duffy Jul 31 '16 at 13:16
  • Or `if [ "$1" = "--force" ] || [ "$1" = "-f" ]; then` – Kusalananda Jul 31 '16 at 13:18
  • The script is designed for Bash (see the other non-POSIX uses in it too), so I don't think POSIX compliance is relevant here – janos Jul 31 '16 at 13:20
  • @janos, the *lack* of POSIX compliance is why it can't be used in other shells, thus why the OP is having problems sourcing it into their non-bash shell. So I'd call it the crux of the issue. – Charles Duffy Jul 31 '16 at 13:26
  • Unless we treat this as a "how should I run this script as an end-user?" question, in which case it's off-topic here and belongs over on SuperUser. – Charles Duffy Jul 31 '16 at 13:26