old-www/LDP/LG/issue11/lg_tips11.html

604 lines
18 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>More 2 Cent Tips & Tricks Issue 11</title>
</head>
<BODY BACKGROUND="../gx/spirbind.gif">
<table>
<tr><td><img src="../gx/blank.gif" width=50></td>
<td>
<H4><IMG ALIGN=MIDDLE SRC="./gx/bat-l.gif">
&quot;Linux Gazette...<I>making Linux just a little less scary!</I>
&quot;<IMG ALIGN=MIDDLE SRC="./gx/bat-r.gif"> </H4>
<hr>
<!-- QUICK TIPS SECTION ================================================== -->
<center><H1><A NAME="tips"><IMG ALIGN=MIDDLE ALT="" SRC="../gx/twocent.gif">More 2&#162; Tips!
</A></H1> <BR>
Send Linux Tips and Tricks to <A HREF="mailto:gazette@ssc.com">
gazette@ssc.com</A>.</center>
<p><hr><p>
<H3>Contents:</H3>
<ul>
<li><a HREF="#xterm">Another XTerm Title Trick</a>
<li><a HREF="#file">File Decompression</a>
<li><a HREF="#quick">Quick Tricks from John Fisk</a>
<li><a HREF="#two">Two Tips for the Price of One</a>
<li><a HREF="#emacs">The Ultimate Emacs Control M Trick</a>
<li><a HREF="#vi">VI Trick</a>
<li><a HREF="#xdm">XDM Replacement</a>
</ul>
<P> <hr> <P>
<!--================================================================-->
</td></tr>
</table>
<a name="xterm">
<p></a>
<table>
<td><img src="../gx/blank.gif" width=50></td>
<td>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">Another XTerm
Titlebar Trick</H3>
<P>
Date: Wed, 2 Oct 1996 16:11:35 -0700 (PDT)<BR>
From: Jonathan Gross <BR>
<P>
I have a quick stupid shell script to change the titlebar on the
fly:
<PRE>
#!/bin/bash
echo "]0;$1"
</PRE>
where the ^[ is done in Emacs by typing C-q Esc and the ^G is done
by typing C-q C-g, or in vi by typing C-v instead of C-q before each
control sequence.
<P>
Then you type:
<PRE>
linux$ titlebar "string for window title"
</PRE>
Where "titlebar" is the name of your shell script. Dumb, simple,
but easy to use...
<PRE>
Jonathan Gross
Specialized Systems Consultants, 206-782-7733
"A jewel mine of courtesies and a living casket of diplomacy"
</PRE>
<P> <hr> <P>
</td></tr>
<tr>
</table>
<a name="file">
<p></a>
<table>
<tr>
<td><img src="../gx/blank.gif" width=50></td>
<td>
<!-- ===================================================================== -->
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">File Decompressing</H3>
<P>
Date: Fri, 27 Sep 1996 08:32:37 +0200 (MET DST) <BR>
From: Xabier Vazquez Gallardo, <A HREF="mailto:sixconse@sc.ehu.es">sixconse@sc.ehu.es </A><BR>
<P>
Hi there:
<P>
Here is a script I wrote two years ago, but I think it can
be useful for everybody. It can also help in learning shell script
programming.
<P>
The function of this script is to help ppl decompressing
compressed files with tar, gzip, compress, arj, zip, etc, and any
combination of these compression tools. Just type "gus filename" and the
script will call the necessary decompression program.
<P>
Thanx in advance, <BR>
Xabier Vazquez Gallardo
<PRE>
------------ 8< --------- 8< ---------- 8< ----------- 8< ------------
#!/bin/sh
# If you are under ULTRIX use /bin/sh5 instead of /bin/sh (too buggy)
################################################################################
# @(#)gus,v 2.8 11/22/1994 (c) XaBier Vazquez Gallardo <sixconse@sc.ehu.es>
# You'll need this external programs:
# gzip, tar, sed, awk, unarj, lha, zoo, unzip, test, pgp, uncompress, echo and
# uudecode. If you don't have all those programs maybe gus won't work.
#
# Program Description:
# Decompress all this kind of files and combinations of them:
# .arc .zip .ZIP .arj .zoo .lzh .lha .lzh .Z .z .tar .tgz .shar .pgp
# .[1-8ln] .man .uu and .uue
# * Man type files will be displayed
#
# Please send suggestions or gub reports to XaBi <sixconse@sc.ehu.es>
# Sorry about my English, but it's better than Spanish, isn't it?
################################################################################
gus_version="V2.8"
gus_date="11/22/1994"
# Show a long help :)
do_help ()
{
echo
echo This script helps you decompressing Unix archives compressed with compress,
echo gzip, tar, shar, lha, arj, zip, zoo, pgp, arc and uuencode. It also formats
echo manual pages. Now you don\'t need to type all those long lines to decompress
echo a tar + gz archive, only type \'gus file\' and it will do all the work.
echo "GUS knows this extensions and combinations of them (tar + gzip, etc):"
echo ".Z .z .zip .arj .zoo .arc .lha .lz .pgp .tar .tgz .shar .[1-8ln] .man .uu .uue"
echo
echo "USAGE: '`basename $0` [-h | [[-r | -rf] f1 [f2] ...]' will decompress f1, f2, ..."
echo " '-h' show you this help"
echo " '-r' remove with prompt compressed file after decompress it"
echo " '-rf' remove without prompt compressed file after decompress it"
echo "ie: '`basename $0` file1 -rf file2 file3' will do this:"
echo " decompress file[123] and remove file[23] without any ask"
echo " *WARNING* Be careful with option '-rf'"
exit 0
}
# Find a file in your path
# input : "filename"
# output: $filresult=full_path/filename || $filename="" + error message
# ie : findfile zip
findfile ()
{
sifs=$IFS
IFS=:
fileresult=""
for dir in $PATH; do
test -z "$dir" && dir=.
if [ -x $dir/$1 ] ; then
fileresult="$dir/$1"
break
fi
done
IFS=$sifs
test -z "$fileresult" && echo ERROR: Can\'t find $1
}
# Change status variables
# input: " | decompress_command_line" \
# " decompress_program_name +" \
# 1 (if gus must create a decompressed file) || 0 (if not) \
# 1 (if decompress program can pipe it result) || 0 (if not) \
# 1 (if decompress program accepts stdin pipes) || 0 (if not)
# output: none
# ie : changevars " | tar xvfo -" " tar +" 0 1 1
changevars ()
{
command=$command$1
message=$message$2
create=$3
exit_f=$4
do_cat=$5
}
# Ask Y/N before remove a file
# input : "filename"
# output : $removeit = 0 (if answer is no) || 1 (if is yes)
# ie : makeask /usr/local/foo.bar.tar
makeask ()
{
exit_ask=0
while [ $exit_ask = 0 ] ; do
echo "Do you want to remove '$1' [Y/N]? \c"
read yesno
case $yesno in
y* | Y*)
removeit=1
exit_ask=1
;;
n* | N*)
removeit=0
exit_ask=1
;;
esac
done
}
# Check program parameters and count files
# input : "command_line_params"
# output : $total_files=num_of_files_to_process || or help_screen
# ie : check_params -rf foo.tar
check_params ()
{
for i in $*
do
case $i in
-rf | -r)
total_files=`expr $total_files - 1`
;;
-h)
do_help
;;
esac
done
}
echo GUS $gus_version [$gus_date] General Unpack Shell for Un*x \(c\) XaBi
total_files=$#
check_params $*
if [ $total_files = 0 ] ; then
echo ERROR: not enough params
echo "TRY : `basename $0` -h"
exit 1
fi
if [ $total_files = 1 ] ; then
echo [ $total_files ] file to process ...
else
echo [ $total_files ] files to process ...
fi
removefile=0
promptbefore=0
for file_tmp in $*
do
case $file_tmp in
-rf)
removefile=1
promptbefore=0
continue
;;
-r)
removefile=1
promptbefore=1
continue
;;
esac
if test -f $file_tmp ; then
exit_f=0
command=""
message=""
do_cat=1
create=1
file=`basename $file_tmp`
while [ $exit_f -eq 0 ] ; do
old_file=$file
extension=`echo $file | sed -e 's/.*\.//'`
if [ "$extension" = "$file" ] ; then
extension=""
else
file=`echo $file | sed -e s/\.$extension$//`
fi
case $extension in
tar)
changevars " | tar xvfo -" " tar +" 0 1 1
;;
Z)
changevars " | uncompress" " compress +" 1 0 1
;;
z | gz)
changevars " | gzip -d" " gzip +" 1 0 1
;;
tgz)
changevars " | gzip -d | tar xvfo -" " tar + gzip +" 0 1 1
;;
uu | uue)
changevars " | uudecode" " uuencode +" 0 1 1
;;
shar)
changevars " | sh" " shar +" 0 1 1
;;
zip | ZIP)
if [ -z "$command" ] ; then
findfile unzip
test ! -z "$fileresult" && changevars $fileresult " zip +" 0 1 0
else
echo ERROR: Can\'t pipe to unzip. File partialy decompressed.
fi
exit_f=1
;;
arj | ARJ)
if [ -z "$command" ] ; then
findfile unarj
test ! -z "$fileresult" && changevars $fileresult" x" " arj +" 0 1 0
else
echo ERROR: Can\'t pipe to unarj. File partialy decompressed.
fi
exit_f=1
;;
arc | ARC)
if [ -z "$command" ] ; then
findfile arc
test ! -z "$fileresult" && changevars $fileresult" x" " arc +" 0 1
0
else
echo ERROR: Can\'t pipe to arc. File partialy decompressed.
fi
exit_f=1
;;
zoo | ZOO)
if [ -z "$command" ] ; then
findfile zoo
test ! -z "$fileresult" && changevars $fileresult" x" " zoo +" 0 1 0
else
echo ERROR: Can\'t pipe to zoo. File partialy decompressed.
fi
exit_f=1
;;
lzh | lha | lz | LZH | LHZ | LZ)
findfile lha
test ! -z "$fileresult" && changevars " | "$fileresult" x -" " lha +" 0 1 1
exit_f=1
;;
pgp)
findfile pgp
if [ ! -z "$fileresult" ] ; then
changevars " | "$fileresult " pgp +" 0 0 1
else
exit_f=1
fi
;;
[1-8nl] | man)
test -z "$command" && changevars " | nroff -man | more" " man +" 0 1 1
exit_f=1
;;
*)
exit_f=1
;;
esac
done
test $create -eq 1 && command=$command" > "$old_file
if [ -z "$message" ] ; then
echo ERROR: Don\'t know how to handle [ $file_tmp ]
else
message=`echo $message | sed -e 's/ +$//'`
echo "File [ `basename $file_tmp` ]"
echo "Type [ $message ]"
if [ $do_cat = 1 ] ; then
command="cat "$file_tmp" "$command
else
command=$command" "$file_tmp
fi
eval $command && {
if [ $removefile = 1 ] ; then
if [ $promptbefore = 1 ] ; then
makeask $file_tmp
test $removeit -eq 1 && rm -f $file_tmp
else
rm -f $file_tmp
fi
fi
} || echo ERROR: [ $file_tmp ] can\'t decompress ...
fi
else
echo ERROR: [ $file_tmp ] Can\'t process it! Exists????
fi
done
</PRE>
<P> <hr> <P>
<!--================================================================-->
</td></tr>
</table>
<a name="quick">
<p></a>
<table>
<tr>
<td><img src="../gx/blank.gif" width=50></td>
<td>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">Quick Tips from John</H3>
Date: Tue, 08 Oct 1996 08:18:39 -0500 (CDT) <BR>
From: John M. Fisk
<A HREF="mailto:fiskjm@ctrvax.Vanderbilt.Edu">fiskjm@ctrvax.Vanderbilt.Edu </A><BR>
<P>
I recently ran across a "Quick Tip" that might be useful to anyone
using the BASH shell. There's a rarely mentioned but very useful feature
that's included with it: an online help function that describes all of
its built-in functions. To use it you simply invoke it as:
<PRE>
% help &lt;builtin&gt;
</PRE>
and it displays a brief usage message. To get a listing of all of the
topics that are available, simply type in:
<PRE>
% help
</PRE>
This displays a listing of all of BASH's builtin functions. So, for
example, if you were interesting in using the "getopts" builtin in order
to parse command line options for a shell script, you'd invoke the help
function as:
<PRE>
% help getopts
</PRE>
which prints a helpful summary of the function and its invocation.
<P>
The other thing I recently ran across was the use of the "$()" construct
in BASH shell programming. When I first started learning shell
programming the construct which I'd seen used for command substitution was
something like:
<PRE>
DATE=`date + "%A %B %C"`
</PRE>
which assigned the output of the date command to the variable DATE. I
recently read that this has been deprecated and the accepted construct now
for command substitution is the use of the dollar sign and parentheses.
The above statement should now be written as:
<PRE>
DATE=$(date + "%A %B %C")
</PRE>
which has the same effect. This works under both BASH and the Korn shell
(I'm not sure if this also works with C-shell derivatives). <BR>
____________________________________________________________John M. Fisk
<P> <hr> <P>
<!--================================================================-->
</td></tr>
</table>
<a name="two">
<p></a>
<table>
<tr>
<td><img src="../gx/blank.gif" width=50></td>
<td>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">Two Tips for the Price of One</H3>
<P>
Date: Fri, 4 Oct 1996 18:28:05 -0500 (CDT) <BR>
From: David Ishee <A HREF="mailto:ishee@erc.msstate.edu">
ishee@erc.msstate.edu</A><BR>
<P>
Just looking at your $0.02 tips and I had some $0.01 tips to add. I liked
the perl trick for removing Control-M characters so I made it an alias in
my .cshrc file (for the tcsh shell):
<PRE>
alias tu "perl -pi.bak -e 's/\r//g;' \!^"
</PRE>
Now type "tu filelist" to run the above command. (tu stands for to Unix)
<P>
Another $0.01 tip:
<P>
When I used the xterm title bar thingy and I was at a VT, the escape
characters would just cause the Linux terminal to beep at me. I now have
this in my .cshrc (for the tcsh shell):
<PRE>
if ($TERM == "xterm") then
alias precmd 'echo -n "\033]2;"`whoami`":"`pwd`"\007"'
endif
</PRE>
This puts my login_name:directory in my title bar, but not when I go to a
Linux VT.
<PRE>
+--------------------------------------------------------------------+
| David Ishee ishee@erc.msstate.edu |
| Mechanical Engineering Senior |
| Mississippi State University OS/2 and Linux user |
+------------- http://www2.msstate.edu/~dmi1/index.html -------------+
</PRE>
<P> <hr> <P>
<!--================================================================-->
</td></tr>
</table>
<a name="emacs">
<p></a>
<table>
<tr>
<td><img src="../gx/blank.gif" width=50></td>
<td>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">The
Ultimate Emacs Control M Trick </H3>
Date: Thu, 3 Oct 1996 10:19:24 -0700 <BR>
From: Rick Bronson <A HREF="mailto:rick@efn.org">rick@efn.org </A><BR>
<P>
Hi,
<P>
Here is the ultimate Emacs Control M Trick:
<P>
Put the following line in your .emacs file:
<PRE>
(require 'dos-mode)
</PRE>
and have dos-mode.el, which for me is in ~/lisp/dos-mode.el, some where
in your path by putting the following line in your .emacs file:
<PRE>
(setq load-path (append load-path (list "/home/rick/lisp")))
</PRE>
That's it! Now you can edit native DOS files without having to do
any conversion at all. You won't see any ^M stuff in the DOS files,
they are removed for you. You can cut and paste between DOS and UNIX
buffers and the ^M stuff is handled automatically.
<P>
dos-mode.el is available in
/ftp@archive.cis.ohio-state.edu:/pub/gnu/emacs/elisp-archive/modes as
dos-mode.el.Z
<PRE>
_
| |
/ /__
.------------------------------------------------------------._______/ (___)
| Rick Bronson rick@efn.org Tel 541-465-9008 _o_ | (___)
| Invivo Research http://www.efn.org/~rick \|/ |_______ (___)
| 745 Foothill Drive "Onde esta dinheiro?" `---' | \_(___)
| Eugene, OR 97405-4651 -- Gal Costa Disk | Golf|
`------------------------------------------------------------'
</PRE>
<P> <hr> <P>
<!--================================================================-->
</td></tr>
</table>
<a name="vi">
<p></a>
<table>
<tr>
<td><img src="../gx/blank.gif" width=50></td>
<td>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">VI Trick</H3>
Date: Sat, 26 Oct 1996 05:11:34 -0500 <BR>
From: John R. Potter <A HREF="mailto:jrpotter@neosoft.com">
jrpotter@neosoft.com</A><BR>
<P>
I thought you might be interested in my favorite vi trick, which is not a
vi trick at all. I spend a lot of time in vi edit sessions, usually with
two files open moving data between them using the named buffers. Often
someone will come in with a 'brush fire' that needs immediate attention and
I really don't want to quit my edit session and lose my buffers. So I put
it to sleep with Control Z. You can start up another vi edit session,
complete with named buffers and everything. They are two complete separate
sessions with no ties between them. When the fire is under control you can
bring back the original session with 'fg'. I know this is a very simple
thing, but for a long time I didn't know you could do it so I would quit
the original session.
<P>
- John Potter
<P> <hr> <P>
<!--================================================================-->
</td></tr>
</table>
<a name="xdm">
<p></a>
<table>
<tr>
<td><img src="../gx/blank.gif" width=50></td>
<td>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">XDM Replacement</H3>
Date: Thu, 03 Oct 1996 23:26:00 -0400 <BR>
From: Jim Nicholson <A
HREF="mailto:pcks@cnj.digex.net">pcks@cnj.digex.net</A><BR>
<P>
I'm not sure how well known it is in the Linux community, but Pierre
Ficheux (<A HREF="mailto:pierre@ai.alienor.fr">pierre@ai.alienor.fr</A>) has written a replacement for the
XDM logon dialog that lets you set up icons for users - sort of like
what you can do on an SGI machine. The file can be had via
ftp://ftp.ibp.fr/pub/linux/tsx-11/sources/usr.bin.X11/xdm-photo-1.1.tar.gz;
more info is available on Pierre's web site
<A HREF="http://alienor.fr/~pierre/index_us.html">
http://alienor.fr/~pierre/index_us.html</A><BR>
<P>
- Jim Nicholson
<P> <hr> <P>
<!--================================================================-->
<A HREF="./index.html"><IMG SRC="../gx/indexnew.gif" ALT="[ TABLE OF
CONTENTS ]"></A> <A HREF="../index.html"><IMG SRC="../gx/homenew.gif"
ALT="[ FRONT PAGE ]"></A> <A HREF="lg_mail11.html"><IMG SRC="../gx/back2.gif" ALT=" Back "></A>
<A HREF="lg_bytes11.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
<P> <hr> <P>
<h5>This page maintained by the Editor of <I>Linux Gazette</I>,
<A HREF="mailto: gazette@ssc.com">gazette@ssc.com</A><BR>
Copyright &copy; 1996 Specialized Systems Consultants, Inc. </H5>
<P>
</td></tr></table>
</body>
</html>