0

I want to make a shell script to run a Makefile.

If I tap this command ./run.sh bonus, The Rule bonus will be applied.

but if I wrote this ./run.sh, the command make will apply.

I try This script but every time the command make apply.

make fclean
if [$1 == "bonus"];
then
    echo "make bonus"
else
    echo "make"
fi
make clean
./cub3D maps/1.cub
Gerhardh
  • 11,688
  • 4
  • 17
  • 39
DarkSide77
  • 719
  • 1
  • 4
  • 21

1 Answers1

1

You have a few problems.

First, you need whitespace around the [ and ] (since you claim ./run.sh bonus works as expected, this is probably an omission from the question, not a problem in your actual script.

Second, == should not be used with [. bash allows it, but = is the only portable equality operator for [. If you want to use ==, use [[ ... ]] instead.

Third, you need to quote $1 with [ so that it doesn't simply "disappear" when you run ./run.sh with no argument.

make fclean
if [ "$1" = bonus ]; then  # or [[ "$1" == bonus ]].
  make bonus
else
  make
fi
make clean

./cub3D maps/1.cub
chepner
  • 497,756
  • 71
  • 530
  • 681