Skip to main content
explain what the command actually does.
Source Link
ilkkachu
  • 147.9k
  • 16
  • 268
  • 441

Assuming bashhistory expansion is enabled, that you're running Bash or some other shell that supports it, that the command is idempotent, and that waiting for it to run a second time is not an issue, you could use the !! form of history expansion to get the last command line again, to run the previous command again in a command substitution:

% python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
/usr/lib/python2.7/site-packages
% cd $(!!)
cd $(python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")
% pwd
/usr/lib/python2.7/site-packages

Assuming bash:

% python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
/usr/lib/python2.7/site-packages
% cd $(!!)
cd $(python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")
% pwd
/usr/lib/python2.7/site-packages

Assuming history expansion is enabled, that you're running Bash or some other shell that supports it, that the command is idempotent, and that waiting for it to run a second time is not an issue, you could use the !! form of history expansion to get the last command line again, to run the previous command again in a command substitution:

% python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
/usr/lib/python2.7/site-packages
% cd $(!!)
cd $(python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")
% pwd
/usr/lib/python2.7/site-packages
Source Link
jsbillings
  • 24.9k
  • 7
  • 58
  • 58

Assuming bash:

% python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
/usr/lib/python2.7/site-packages
% cd $(!!)
cd $(python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")
% pwd
/usr/lib/python2.7/site-packages