I need to create a shell script that checks for the presence of a file and if it doesn't exist, creates it and moves on to the next command, or just moves on to the next command. What I have doesn't do that.
#!/bin/bash
# Check for the file that gets created when the script successfully finishes.
if [! -f /Scripts/file.txt]
then
: # Do nothing. Go to the next step?
else
mkdir /Scripts # file.txt will come at the end of the script
fi
# Next command (macOS preference setting)
defaults write ...
Return is
line 5: [!: command not found
mkdir: /Scripts: File exists
No idea what to do. Every place a Google search brings me indicates something different.
touch
the file and skip the conditional?[
and!
), but it's probably helpful to point out here that[
is an actual command on Unix. A Unix command requires some whitespace between the command name and its arguments. Yes, it's a Bash builtin, too, but there's also a binary at/usr/bin/[
on most systems.