old-www/HOWTO/Bash-Prog-Intro-HOWTO-2.html

63 lines
2.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
<TITLE>BASH Programming - Introduction HOW-TO: Very simple Scripts</TITLE>
<LINK HREF="Bash-Prog-Intro-HOWTO-3.html" REL=next>
<LINK HREF="Bash-Prog-Intro-HOWTO-1.html" REL=previous>
<LINK HREF="Bash-Prog-Intro-HOWTO.html#toc2" REL=contents>
</HEAD>
<BODY>
<A HREF="Bash-Prog-Intro-HOWTO-3.html">Next</A>
<A HREF="Bash-Prog-Intro-HOWTO-1.html">Previous</A>
<A HREF="Bash-Prog-Intro-HOWTO.html#toc2">Contents</A>
<HR>
<H2><A NAME="s2">2. Very simple Scripts</A> </H2>
<P> This HOW-TO will try to give you some hints about shell script
programming strongly based on examples.
<P> In this section you'll find some little scripts which
will hopefully help you to understand some techniques.
<P>
<H2><A NAME="ss2.1">2.1 Traditional hello world script</A>
</H2>
<P>
<BLOCKQUOTE><CODE>
<PRE>
#!/bin/bash
echo Hello World
</PRE>
</CODE></BLOCKQUOTE>
<P>
<P> This script has only two lines.
The first indicates the system which program
to use to run the file.
<P> The second line is the only action performed by this script,
which prints 'Hello World' on the terminal.
<P> If you get something like <I>./hello.sh: Command not found.</I>
Probably the first line '#!/bin/bash' is wrong, issue whereis bash or see
'finding bash' to see how sould you write this line.
<H2><A NAME="ss2.2">2.2 A very simple backup script</A>
</H2>
<P>
<BLOCKQUOTE><CODE>
<PRE>
#!/bin/bash
tar -cZf /var/my-backup.tgz /home/me/
</PRE>
</CODE></BLOCKQUOTE>
<P> In this script, instead of printing a message on the terminal,
we create a tar-ball of a user's home directory. This is NOT intended
to be used, a more useful backup script is presented later in this
document.
<HR>
<A HREF="Bash-Prog-Intro-HOWTO-3.html">Next</A>
<A HREF="Bash-Prog-Intro-HOWTO-1.html">Previous</A>
<A HREF="Bash-Prog-Intro-HOWTO.html#toc2">Contents</A>
</BODY>
</HTML>