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 ?
- 4,991
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
- 136,215
- 21
- 243
- 336
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.
- 4,991
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
- 36,399
~/.bashrcfile, such asalias ls='ls --color=auto'andalias grep='grep --color=auto'(typealiaswithout any arguments to see a list of the current ones). – steeldriver Apr 01 '15 at 23:54exitis a bash builtin - for a normal command where you wanted it to do something similar you probably could enter the command's full path (e.g.alias firefox='clear; sleep 2; /usr/bin/firefox'). The above may work anyway :). An alternative toexitthat may work would be something along the lines ofkill -SIGINT $$,kill -SIGKILL $$to kill the process's PID (SIGKILLworks but does not exit cleanly, other stuff seems to get ignored by the terminal - stuff on signals here: http://en.wikipedia.org/wiki/Unix_signal) – Wilf Apr 01 '15 at 23:57unaliascommand e.g.unalias exit. You can execute the original command without unaliasing by preceding the command with a backslash, i.e.\exit. – steeldriver Apr 02 '15 at 00:21