old-www/HOWTO/Wearable-HOWTO-8.html

150 lines
6.9 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
<TITLE>Wearable-HOWTO.: CLI only</TITLE>
<LINK HREF="Wearable-HOWTO-9.html" REL=next>
<LINK HREF="Wearable-HOWTO-7.html" REL=previous>
<LINK HREF="Wearable-HOWTO.html#toc8" REL=contents>
</HEAD>
<BODY>
<A HREF="Wearable-HOWTO-9.html">Next</A>
<A HREF="Wearable-HOWTO-7.html">Previous</A>
<A HREF="Wearable-HOWTO.html#toc8">Contents</A>
<HR>
<H2><A NAME="s8">8. <CODE>CLI</CODE> only</A></H2>
<P>
<P>
<H2><A NAME="ss8.1">8.1 What is <CODE>CLI</CODE>?</A>
</H2>
<P>
<P><CODE>CLI</CODE> is a shorthand to the Comand Line Interface. When you are
installing Linux on your computer without X, you will work in <CODE>CLI</CODE>-mode! Perhaps
you will shout "oh... that's horrible", but your computer will shout "yeah... I
have more %CPU and %mem to work and to play!".
<P>
<H2><A NAME="ss8.2">8.2 Why does one talk about <CODE>CLI</CODE> here?</A>
</H2>
<P>Some wearables may have problems with graphics chipsets, disk and memory space and battery-life. If you work in
text-mode, you will save battery-life and disk usage as well as lot of memory and CPU Cycles. And if you don't
have to install graphic interfaces, you will save a little disk-space
too. Consequently,
you gain some space for your data. But you
may feel that in text-mode, nothing can be done. As you will see the same things can
be done in text-mode and graphic environment. Only things are thought
differently.
<P>
<H2><A NAME="ss8.3">8.3 What can be done in text-mode?</A>
</H2>
<P>We have to think with what we have few programs who can
communicate between them by input/output canals. This type of
environment implies that we must use all our fingers to work, we can even get rid of the mouse.
As in <CODE>X</CODE>, you have editors (<CODE>Vi</CODE>, <CODE>Emacs</CODE>,
<CODE>Jed</CODE>...), games ( BTW wearables are
the game by themselves ), viewers/browsers ( <CODE>?less</CODE>, <CODE>?more</CODE>, <CODE>lynx</CODE>, <CODE>links</CODE>
...), file
managers ( <CODE>mc</CODE>...) and more. Also, some people may believe that <CODE>CLI</CODE> is cool but
it's difficult to learn all configurations and options of all
commands. The learning curve is acutally steeper, but when you have learnt that, you will work
faster and the faster the work is done the better it is with a wearable
. We'll see examples which accelerate our personal work.
<H2><A NAME="ss8.4">8.4 Bunch of utilities</A>
</H2>
<P>
<H3>Shell and script-language</H3>
<P>Bases of <CODE>UNIX</CODE> are its powerful shells. With shells you can do more
than the poor batch-language of Microsoft.
<CODE>UNIX</CODE> gives a lot of powerful shells (<CODE>tcsh</CODE>, <CODE>ksh</CODE>, <CODE>bash</CODE>...),
but I always
work with <CODE>sh</CODE>. I know it is old and less featured than its big brothers
but it is on every Unices. In <CODE>sh</CODE>, there are often used
functions/commands (<CODE>echo</CODE>, <CODE>test</CODE>). Why do I say that? You can notice
that <CODE>GNU</CODE> gives a program <CODE>echo</CODE> and <CODE>test</CODE> and I say: "if we can eliminate
these programs, we can free disk-space... ok, not too much but about
20k.". And some versions of <CODE>sh</CODE> are very economical.
The language of shell (script) is like a small programming language:
you can used loops (<CODE>for</CODE>, <CODE>while</CODE>), user interactions (<CODE>read</CODE>),
I/O (&lt;
>)... To learn scripting, you just have to type: <CODE>man sh</CODE> (or <CODE>tcsh</CODE>.... but
more complex...).
Stupid example of a little script:
<CODE>for i in * .[^.]*; do echo $i; done</CODE>
(simple <CODE>ls</CODE>).
<P>
<H3>Must I learn <CODE>sed</CODE> and <CODE>AWK</CODE>?</H3>
<P>In the Unix's world, we hear a lot about <CODE>AWK</CODE> and <CODE>sed</CODE>. These programs
are generic and can be used for a lot of things. <CODE>GNU</CODE> gives a bunch of
utilities that can replace <CODE>sed</CODE> and <CODE>AWK</CODE> (<CODE>dd</CODE>, <CODE>cut</CODE>, <CODE>seq</CODE>, ...).
Why <CODE>dd</CODE> will you ask ?
<P><CODE>dd</CODE> have a little function that is fine: conversion
low/up case. An example:
<P>There are names in this directory that are in uppercase but you want
to change them to lowercase. With <CODE>AWK</CODE>, you must type: <CODE>for i in *; do
mv "$i" "`echo $i | awk '{print tolower($0)}'`"; done</CODE>; with <CODE>sed</CODE>
you must enumerate all letters; with dd, it's very easy, I think:
<CODE>for i in *; do mv "$i" "`echo $i | dd conv=lcase`"; done</CODE>
<P><CODE>cut</CODE> is a program to print columns of a text. Also, if you must print
different columns of a line, you can use <CODE>cut</CODE>. <CODE>cut</CODE> performs
better than <CODE>AWK</CODE> in this case if you want the job to be done fastly and efficiently because
<CODE>cut</CODE> is dedicated to this work. For the same task, you may use
the shell's internal commands too (you can, if you assign a value to
the <CODE>IFS</CODE> variable). Here is an example in <CODE>AWK</CODE>, <CODE>cut</CODE> and <CODE>sh</CODE>. We
want only to display a list with <CODE>login : identity</CODE> fields:
<UL>
<LI>in AWK:
<PRE>
awk -F: '{ print $1" : "$5}' /etc/passwd
</PRE>
</LI>
<LI>with <CODE>cut</CODE>:
<PRE>
while read line; do echo "`echo $line | cut -d: -f 1` : `echo $line | cut -d: -f 5`"; done &lt; /etc/passwd
</PRE>
</LI>
<LI>only with sh:
<PRE>
IFS=':'; while read a b c d e f; do echo "$a : $e"; done &lt; /etc/passwd; IFS=' '
</PRE>
</LI>
</UL>
Generally, you haven't to learn <CODE>AWK</CODE>. I think that you can always do
things without <CODE>AWK</CODE>. (OK, sometimes, <CODE>AWK</CODE> is easier.)
<P>About <CODE>sed</CODE>, the drawback is that you must work with temporary
files. If you want to save disk-space and to edit files in
command-line, you can use <CODE>ex</CODE>, the script version of
<CODE>vi</CODE>. Also, <CODE>sed</CODE> can be used but not necessarily.
<H3>Redundancies in utilities?</H3>
<P>If disk-space is very important, you can delete certain programs which perform task
that can be done by others programs. For example: if you have to
use <CODE>dd</CODE>, you don't need <CODE>cat</CODE>, if you have <CODE>vi</CODE>,
you don't need <CODE>ed</CODE> (help me to find other examples...).
<P>
<P>
<H2><A NAME="ss8.5">8.5 Aliases or scripts?</A>
</H2>
<P>Scripts are more powerful than aliases. But scripts eat disk-space and
are loaded each time they are used. Aliases eat memory-space and if
you are in <CODE>CLI</CODE>, you have all the memory for you! Aliases are faster
than scripts because they are loaded from memory and not from disk.
<P>Generally, shells offer you another alternative for aliases/scripts:
functions. Functions have power of scripts with the convenience to eat
only memory-space. To learn aliases and functions, you can look at the
manpages.
<P>
<HR>
<A HREF="Wearable-HOWTO-9.html">Next</A>
<A HREF="Wearable-HOWTO-7.html">Previous</A>
<A HREF="Wearable-HOWTO.html#toc8">Contents</A>
</BODY>
</HTML>