我正在使用 Jenkins 构建项目。我能够构建项目。我需要将 war 文件复制到目标位置。
我可以使用 cp source_file_location target_file_location
复制 .war 文件
它会完成工作。
但是我想检查文件是否已经存在显示消息找到旧文件然后删除旧文件并将新文件复制到目标位置。
并将目标位置文件夹压缩并复制到x处。
真的很抱歉。看来我刚刚给出了要求。除了一些基本命令外,我真的不知道如何编写 shell 脚本。 有谁能够帮助我?
最佳答案
好的,接下来就是您将需要的命令的一些提示。这应该足以创建您的第一个 bash 脚本。
But I want to check if the file already exist
查看 test 命令(或等效的 [ -f file_exists ])。例如:
if [ ! -f /tmp/foo.txt ]; then
echo "File not found!"
fi
show message old file found
echo "My message"
then delete the old file
rm file (or -r for directory)
and copy the new file in target location.
这部分认为你已经知道怎么做了
如果您对任何命令有任何疑问,请尝试查阅命令手册。一般来说,它非常简单明了。以下是一个很好的 bash 编程教程的链接。
关于linux - 如何为 Redhat Linux bash shell 编写 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32863194/