Menu

Cool Commands

Rocky Bernstein

Here we list some of the cooler commands that you might not be familiar with.

See also:

Auto Evaluation

The debugger has a mode where anything you type into the debugger that recognized as a debugger command is automatically evaluated as bash code. The way the debugger determines if something is a debugger command is by looking up the first blank-delimited token in a command table and failing to find anything there, in an alias table. Aliases are customizable. (See the help for alias and unalias.) Commands are not once they are added.

When this mode is set, if what you type is erroneous the corresponding bash error message is displayed and this sometime might be confusing if what you thought you typed was a debugger command rather than a bash command.

$ bashdb /etc/init.d/apparmor status
Copyright 2008, 2009, 2010, 2011 Rocky Bernstein
This is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.

(/etc/init.d/apparmor:35):
. /etc/apparmor/functions
bashdb<1> lis 5
lis 5
** Undefined command "lis". Try "help".
bashdb<1> set autoeval on
set autoeval on
Evaluate unrecognized commands is on.
bashdb<2> lis 5
lis 5
/tmp/bashdb_eval_1713:2: command not found: lis
$? is 127
bashdb<3> list 5
list 5
  1:    #!/bin/sh
  2:    # ----------------------------------------------------------------------
  3:    #    Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
  4:    #     NOVELL (All rights reserved)
  5:    #    Copyright (c) 2008, 2009 Canonical, Ltd.
  6:    #
  7:    #    This program is free software; you can redistribute it and/or
  8:    #    modify it under the terms of version 2 of the GNU General Public
  9:    #    License published by the Free Software Foundation.
 10:    #
bashdb<4>

Because of the above potential confustion and because entering commands to be evaluated can be distructive, this mode is turned off by default. However most non-novice users prefer to set this mode on.

Auto list

Normally only the source code line to be displayed is listed in stopping in the debugger. However it is possible to automatically list more context automatically on each stop. For this use set autoeval.

Here is a sample session:

$ bashdb hanoi.sh 
bashdb hanoi.sh 
zsh debugger, bashdb, release 0.07

Copyright 2008, 2009, 2010, 2011 Rocky Bernstein
This is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.

(/hanoi.sh:6):
init () { if (( $tracing )) then _Dbg_set_linetrace=1 fi }
bashdb<1> set autolist on
set autolist on
Auto run of 'list' command is on.
bashdb<2> s
(/hanoi.sh:13):
hanoi () {
    typeset -i n=$1
    typeset -r a=$2
    typeset -r b=$3
    typeset -r c ...
  8:      if (( $tracing )) ; then
  9:        _Dbg_set_linetrace=1
 10:      fi
 11:    }
 12:    
 13: => hanoi() { 
 14:      typeset -i n=$1
 15:      # _Dbg_set_trace
 16:      typeset -r a=$2
 17:      typeset -r b=$3
bashdb<3> s
(/hanoi.sh:30):
typeset -i max=3
 25:           hanoi $n $c $b $a
 26:        fi
 27:      fi
 28:    }
 29:    
 30: => typeset -i max=3
 31:    typeset -i tracing=0
 32:    if [[ "$1" = 'trace' ]] ; then
 33:      if [[ -n $2 ]] ; then
 34:          abs_top_builddir=$2
bashdb<4> s
(/hanoi.sh:31):
typeset -i tracing=0
 26:        fi
 27:      fi
 28:    }
 29:    
 30:    typeset -i max=3
 31: => typeset -i tracing=0
 32:    if [[ "$1" = 'trace' ]] ; then
 33:      if [[ -n $2 ]] ; then
 34:          abs_top_builddir=$2
 35:      elif [[ -z $builddir ]] ; then

If you want to change the number of context lines use set listsize:

bashdb<5> set listsize 4
bashdb<6> step
(/hanoi.sh:32):
if [[ "$1" = 'trace' ]]
then
    if [[ -n $2 ]]
    then
        abs_top_builddir=$2 
     ...
 30:    typeset -i max=3
 31:    typeset -i tracing=0
 32: => if [[ "$1" = 'trace' ]] ; then
 33:      if [[ -n $2 ]] ; then
bashdb<7> step
(/hanoi.sh:32):
[[ "$1" = 'trace' ]]
 30:    typeset -i max=3
 31:    typeset -i tracing=0
 32: => if [[ "$1" = 'trace' ]] ; then
 33:      if [[ -n $2 ]] ; then
bashdb<9>

To be continued...


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.