Bash


Forum: DSL Tips and Tricks
Topic: Bash
started by: mikshaw

Posted by mikshaw on July 31 2005,18:57
If you have created an alias of a comand with the same name as the command (example: alias ls='ls -al'), you can bypass the alias with a prefixed backslash (example: \ls), which runs the command in its default state.

------------------------

Type a "cd newdirectory; command" command in parentheses to bounce you back to your previous PWD after the command has run:
Code Sample
$ cd
$ pwd
/home/dsl
$ (cd downloads/Fluxbox/styles; mkdir newstyles)
$ pwd
/home/dsl
This isn't particularly efficient in many situations, but it works.

------------------------

Brace expansion can save a lot of typing (and bytes in a script).
This means using curly braces to list several unique parts of an otherwise identical command so you don't need to do a lot of retyping.

A couple of examples. First line is the standard command, and the second is the same using brace expansion:

Code Sample
cp filename.one filename.two
cp filename.{one,two}

Code Sample
echo "foo foobar"
echo foo{,bar}


------------------------

reverse-i-search allows you to use auto-completion to cue up past commands.  If you have a command you used way back you don't want to bother using the up key to retrieve it.  Instead press Ctrl+r and then type a couple of characters.  Bash will search through its history and present you with a command including that string.

------------------------

The CDPATH variable can be utilized much like PATH and LD_LIBRARY_PATH.  Set up a CDPATH variable something like this:
export CDPATH=/usr/X11R6/lib:/path/to/something/else
Then do "cd fonts" and you should be taken to /usr/X11R6/lib/fonts

------------------------

Posted by JO+ on Aug. 25 2005,12:16
Thanks - you showed me some new 'goodies'!

By the way - for all of you who want to get more into the commandline (mainly bash) - I use a compendium with a lot of examples that helped (and still helps) me a lot:

'Advanced Bash-Scripting Guide' by Mendel Cooper
e.g. at   < http://www.tldp.org/LDP/abs/html/ >

you can read it online or download it in different formats.

Posted by NotTheMama on Aug. 25 2005,12:56
Kewl,

At first I thought they would only work in bash. But sh on HPUX also accepts CDPATH and Brace expansion.

An trick of mine:
When you want to find a process with ps you can do something like this:
ps -ef | grep init | grep -v grep
But this also works great:
ps -ef | grep [i]nit
And you do not get that line with grep...

Another great command is fold. Especially when printing ascii files with lines longer than say 80 chars. Some printer cut a line at 80 chars..

Futher more I always use sed & awk.. Great programs...

Just my $0,02

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.