linux - 如何为 Redhat Linux bash shell 编写 shell 脚本

标签 linux bash shell jenkins

我正在使用 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 编程教程的链接。

http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html

关于linux - 如何为 Redhat Linux bash shell 编写 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32863194/

相关文章:

linux - 按第二字段和第三字段的乘积排序(Linux)

linux - -f 、 -s 选项如何与 uniq 命令一起使用?

linux - 如何在 shell 脚本中获取 awk 的输出到数组中

c++ - 释放我的 *.so 文件时应该使用哪个版本的 glibc?

linux - 在 C 编程中如何获取传递给程序的命令行参数

linux - 替换模板文件中的 bash 变量

git pull 检查文件是否改变 bash

linux - Hydra http 连接失败

c++ - gdb - 多线程和共享库

c - 使用 openssl evp api(aes256cbc) 加密文件的问题