问题
I want to create an alias for pagsh
that will immediately get me the admin kerberos ticket.
The problem is that I can't figure out how to specify a command for the bash
to run, but still continue with the interactive session after the command is done.
My current shot is:
alias admin=pagsh -c "bash -c \"kinit xtoth1@ADMIN.META\""
but bash
logically ends right after kinit
is done. How can I push a custom command into a begging of an interactive session of bash? I still need to run .bashrc normally, therefore I can't use --rcfile
回答1:
My advice would be using a custom bashrc file with --rcfile
that sources your .bashrc, ex :
alias admin=pagsh -c "bash --rcfile myrc"
myrc :
source ~/.bashrc
kinit xtoth1@ADMIN.META
回答2:
If what you need is only a line or two, you can use the cool bash feature of "Process Substitution"[1] to provide it right on the invocation line. e.g. (to run a bash in a specific python virtualenv):
bash --rcfile <(echo '. ./pyvenv/bin/activate')
multiple lines are not a problem, nor is using vars or helpers:
bash --rcfile <(echo echo "Starting at `date`"; echo cd $HOME)
[1] man bash
and look for "Process Substitution". Note that this is not supported on all systems, but it should work on all Linux.
回答3:
What about following?
alias admin='pagsh -c "bash -c \"kinit xtoth1@ADMIN.META; exec bash\""'
or even
alias admin='pagsh -c "kinit xtoth1@ADMIN.META; exec bash"'
might work. (I do not have working openafs environment around to test it properly.)
来源:https://stackoverflow.com/questions/4584736/bash-execute-command-but-continue-with-interactive-session