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 !!
开发者_StackOverflow中文版 inside .bashrc but this simply gives me !!
as title. Any ideas?
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.
not sure exactly what you need, but it should be in here -- try it :)
#!/bin/bash
echo "# arguments called with ----> ${@} "
echo "# \$1 -----------------------> $1 "
echo "# \$2 -----------------------> $2 "
echo "# path to me ---------------> ${0} "
echo "# parent path --------------> ${0%/*} "
echo "# my name ------------------> ${0##*/} "
okay - now that you've clarified your question, I'll offer a different answer.
Actually, the value you want isn't available as an environment variable, but how about this:
tail -n 1 $HOME/.bash_history
am I getting warmer? :)
edit:
note, if you want to use this in your PROMPT_COMMAND
, what you'll need to do it this:
export PROMPT_COMMAND='history -a; tail -n 1 $HOME/.bash_history'
hope this helps :)
精彩评论