I just wants to modify a bash shell command like exit so when i write exit in the terminal it clears the screen, and echo some text, wait 2 seconds, then execute the exit function.
So is there any way to modify a shell command on Ubuntu, if there is away how ?
- 5,139
3 Answers
You can use a shell alias
alias exit='clear; sleep 2; exit'
To make it permanent, add the alias to the bottom of the ~/.bashrc file. see this thread for help
- 142,475
I have found a workaround instead of editing the exit bash command,
trap 'clear; ~/ascii3.sh; spd-say "Exit"; sleep 2' EXIT
by using a trap to the exit in the terminal and i put it in the end of the .pashrc file and it works.
And the ascii3.sh:
echo -e "\033[01;31m" echo " _ _ __ _ _ ____ __ __ _ __ ___ ____ ____ __ _ _ _ " echo "/ )( \ / _\ / )( \( __) / _\ ( ( \( )/ __)( __) ( \ / _\ ( \/ )/ \ " echo ") __ (/ \\\ \/ / ) _) / \ / / )(( (__ ) _) ) D (/ \ ) / \_/ " echo "\_)(_/\_/\_/ \__/ (____) \_/\_/ \_)__)(__)\___)(____) (____/\_/\_/(__/ (_) "
I think the question i asked was a very bad one as it didn't reflect my thoughts but i won't change it nor the answer i just put this answer here for anyone who want it.
- 5,139
You cannot easily modify a command, but you can replace a command.
# You only need this one time:
mkdir --mode=755 $HOME/bin
# You need this command once per login (or in $HOME/.bashrc)
PATH="$HOME/bin:$PATH"
Then any executable file/script in $HOME/bin will override any command with the same name.
When you type a command, the shell looks for an executable file by that name in each of the directories in $PATH.
Unfortunately, your example exit is a "Shell builtin" (see man bash) and is not sought along $PATH, rather it is handled by the shell internally. To override exit you will have to define a shell function or alias(see man bash) in your $HOME/.bashrc
- 37,856