简体   繁体   中英

How do I write shell script for Redhat Linux bash shell

I am using Jenkins to build project. I am able to build Project. I need to copy the war file in target location. I can copy the .war file using cp source_file_location target_file_location it will do the job. 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.

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. 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.

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:

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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