I need to avoid executing a specific command in a bash script.
I was thinking of using the preexec trap for this.
Say I want to avoid the 'source' command for axample only. What I did is basically the following:
#!/bin/bash
function preexec ()
{
if test $( echo "$BASH_COMMAND" | cut -d " " -f1 ) == "source"
then
echo ">>> do not execute this"
else
echo ">>> execute this"
fi
}
trap 'preexec' DEBUG
echo "start"
source "source.sh"
echo "go on"
exit 0
the idea works fine, but at the moment I don’t know how to avoid executing the specified command.
Any idea how to solve this?
source
share