小编jrw*_*jrw的帖子

如果文件不存在,Shell 脚本会创建一个文件吗?

我需要创建一个 shell 脚本来检查文件是否存在,如果文件不存在,则创建它并继续执行下一个命令,或者只是继续执行下一个命令。我所拥有的不会那样做。

#!/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 ...
Run Code Online (Sandbox Code Playgroud)

回报是

line 5: [!: command not found
mkdir: /Scripts: File exists
Run Code Online (Sandbox Code Playgroud)

不知道该怎么办。谷歌搜索给我带来的每个地方都表明了一些不同的东西。

osx bash shell-script

41
推荐指数
4
解决办法
13万
查看次数

标签 统计

bash ×1

osx ×1

shell-script ×1