Showing posts with label shell. Show all posts
Showing posts with label shell. Show all posts

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

Shell script parameters - a simpler way


#!/bin/sh

for param in "$@"; do
eval "$param"
done

param1=${param1:-param1}
param2=${param2:-param2}
param3=${param3:-param3}

echo $param1 $param2 $param3

Usage:


param.sh param1=<param1> param2=<param2> param3=<param3>