This commit is contained in:
gferg 2000-06-21 17:28:14 +00:00
parent 29e7f5440e
commit 99be51f638
1 changed files with 69 additions and 4 deletions

View File

@ -9,7 +9,7 @@
<article>
<title>BASH Programming - Introduction HOW-TO</title>
<author>by Mike G <tt/mikkey@dynamo.com.ar/</author>
<date>v0.05, 20 June 2000</date>
<date>v0.06, 21 June 2000</date>
<abstract>
This article intends to help you to start programming
basic-intermediate shell scripts. It does not intend to be an
@ -388,6 +388,23 @@ Conditionals
fi
</verb></tscreen>
</sect1>
<!--
<sect1>
Sample: testing if a file exists
<P> one more thank to mike
<tscreen><verb>
#!/bin/bash
FILE=~/.basrc
if [ -f $FILE ]; then
echo file $FILE exits
else
echo file not found
fi
if [ 'test -f $FILE']
</verb></tscreen>
</sect1>
-->
</sect>
<!-- Loops : for, while and until -->
@ -570,16 +587,61 @@ Misc
"echo 3/4|bc -l", it would properly return 0.75.
</sect1>
<sect1>
Finding bash
<P> From a message from mike (see Thanks to)
<P> you always use #!/bin/bash .. you might was to give an example of
<P> how to find where bash is located.
<P> 'locate bash' is preferred, but not all machines have locate.
<P> 'find ./ -name bash' from the root dir will work, usually.
<P> Suggested locations to check:
<P> ls -l /bin/bash
<P> ls -l /sbin/bash
<P> ls -l /usr/local/bin/bash
<P> ls -l /usr/bin/bash
<P> ls -l /usr/sbin/bash
<P> ls -l /usr/local/sbin/bash
<P> (can't think of any other dirs offhand... i've found it in
<P> most of these places before on different system).
</sect1>
<!-- Capturing a commands output -->
<sect1>
Capturing a commands output
<P> __TO-DO__
Getting the return value of a program
<P> In bash, the return value of a program is stored in a special variable called $?.
<P> This illustrates how to capture the return value of a program, I assume that the directory
/dada does not exist. (This was also suggested by mike)
<tscreen><verb>
#!/bin/bash
cd /dada &> /dev/null
echo rv: $?
cd $(pwd) &> /dev/null
echo rv: $?
</verb> </tscreen>
</sect1>
<!-- Capturing a commands output -->
<sect1>
Capturing a commands output
<P> This little scripts show all tables from all databases (assuming you got MySQL installed).
Also, consider changing the 'mysql' command to use a valid username and password.
<tscreen><verb>
#!/bin/bash
DBS=`mysql -uroot -e"show databases"`
for b in $DBS ;
do
mysql -uroot -e"show tables from $b"
done
</verb></tscreen>
</sect1>
<!-- Multiple source files -->
<sect1>
Multiple source files
<P> __TO-DO__
<P> You can use multiple files with the command source.
<P> __TO-DO__
</sect1>
</sect>
@ -827,6 +889,9 @@ About the document
<item> Jon Abbott for sending comments about evaluating arithmetic expressions.
<item> Laurent Martelli for translating this document to French (soon here the URL)
<item> Felix Hudson for writing the <it/renna/ script
<item> Mike (pink) made some suggestions about locating bash and testing files
</itemize>
</sect1>
<sect1>