Tuesday, June 23, 2009

Debug bash function interactively


#!/bin/bash

# processing command line parameters
if [ $# -eq 2 ]; then
p1=$1
p2=$2
fi

# setup some environment
export A=a
export B=b

tmpfile=/tmp/myshell-$$-$RANDOM

trap "rm $tmpfile" EXIT

cat <<EOF > $tmpfile
if [ -f /etc/bash.bashrc ]; then
source /etc/bash.bashrc
fi

if [ -f $HOME/.bashrc ]; then
source $HOME/.bashrc
fi

source <shell functions in this file>

export PS1="My Shell$ "
EOF

/bin/bash --rcfile $tmpfile

No comments: