简体   繁体   English

我如何为Redhat Linux bash shell编写shell脚本

[英]How do I write shell script for Redhat Linux bash shell

I am using Jenkins to build project. 我正在使用詹金斯来构建项目。 I am able to build Project. 我能够构建Project。 I need to copy the war file in target location. 我需要将war文件复制到目标位置。 I can copy the .war file using cp source_file_location target_file_location it will do the job. 我可以使用cp source_file_location target_file_location复制.war文件,它将完成这项工作。 But I want to check if the file already exist show message old file found then delete the old file and copy the new file in target location. 但是我想检查文件是否已存在,显示找到旧消息消息,然后删除旧文件并在目标位置复制新文件。

and zip the target location folder and copy in x place. 并压缩目标位置文件夹,然后复制到x位置。

I am really sorry. 真的对不起。 It seems I have just given the requirement. 看来我已经给出了要求。 I really don't know how to write shell script except some basic command. 除了一些基本命令外,我真的不知道该如何编写shell脚本。 can any body help me? 有谁能够帮助我?

Ok, then just some hints of the commands that you will need. 好的,然后只是您需要的命令的一些提示。 This should be enough to create your first bash script. 这足以创建您的第一个bash脚本。

But I want to check if the file already exist 但是我想检查文件是否已经存在

Take a look to the test command (or the equivalent [ -f file_exists ]. As an example: 看一下测试命令(或等效的[-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. 并将新文件复制到目标位置。

This part think you already know ho do it 这部分以为您已经知道怎么做

If you have any doubt about any command, just try to consult the command manual. 如果您对任何命令有疑问,请尝试查阅命令手册。 In general it's very easy and straightforward. 总的来说,这非常容易和直接。 Following is a link to a good bash programming tutorial. 以下是一个好的bash编程教程的链接。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM