Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash - how to find current shell command

When I run a command, I need to set some shell environment variable that holds the current command from inside ".bashrc". Actually I need to update PROMPT_COMMAND whenever a command is run, and I need the whole command line, from where I will pick relevant value.

PROMPT_COMMAND='TITLE=`echo !!`; echo $TITLE;'

I tried using echo !! inside .bashrc but this simply gives me !! as title. Any ideas?

like image 311
Neo Avatar asked Feb 22 '11 11:02

Neo


People also ask

How do I know my current shell?

ps -p $$ – Display your current shell name reliably. echo "$SHELL" – Print the shell for the current user but not necessarily the shell that is running at the movement. echo $0 – Another reliable and simple method to get the current shell interpreter name on Linux or Unix-like systems.

How do you find the PID of a current terminal?

You can use echo $$ to get the PID of the current Bash shell you are using.

What is shell name?

The origin of the Shell name can be traced back to the seashells that Marcus Samuel senior imported from the Far East during the late 19th Century. When his sons Marcus junior and Samuel were looking for a name for the kerosene that they were exporting to Asia, they chose Shell.

How do I change my current shell?

To change your shell use the chsh command: The chsh command changes the login shell of your username. When altering a login shell, the chsh command displays the current login shell and then prompts for the new one.


1 Answers

If you're trying to update the title of the xterm, you can use a DEBUG trap:

trap 'echo "$BASH_COMMAND"' DEBUG

See this blog post.

like image 86
Dennis Williamson Avatar answered Oct 14 '22 11:10

Dennis Williamson