Assign bash command to variable

Hi

I am trying to write a function that needs to be able to assign the last run shell command to a variable. The actual command string itself not the exit code of the command.

I am using the bash command recall ability to do this as follows:

alias pb='ps | grep ash' #Last command string entered

VAR1="!!" #Method used to catch the last command string

Although this does work to capture the last run command, I have a feeling this is not very efficient.
Does anyone here have any suggestions or comments?

Thanks

I don't have/use ash, but this works for bash:

LL=`history 2 |sed '1 s/^ *[0-9]\+ *//;q'`

(This is assuming an interactive shell.)

Thanks otheus.. thats a much nicer way of doing it. Btw I meant to type bash not ash, I have never used the ash shell.. Think i might try it out now just for fun.

Just don't get burnt! :wink: