Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Bash, Tips for commandline and shell scripts< Next Oldest | Next Newest >
mikshaw Offline

Group: Members
Posts: 4856
Joined: July 2004
Posted: July 31 2005,18:57 QUOTE

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
$ (cd downloads/Fluxbox/styles; mkdir newstyles)
$ pwd
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.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


Back to top
Profile PM WEB 
JO+ Offline

Group: Members
Posts: 15
Joined: June 2005
Posted: Aug. 25 2005,12:16 QUOTE

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

you can read it online or download it in different formats.
Back to top
Profile PM 
NotTheMama Offline

Group: Members
Posts: 42
Joined: April 2005
Posted: Aug. 25 2005,12:56 QUOTE


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
Back to top
Profile PM 
2 replies since July 31 2005,18:57 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Quick Reply: Bash

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code