I want to create an alias for pagsh
that will immediately get me the admin kerberos ticket.
我想为pagsh创建一个别名,它会立即获得admin kerberos票证。
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.
问题是我无法弄清楚如何指定bash运行的命令,但在命令完成后仍然继续交互式会话。
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
但是bash逻辑上在kinit完成后立即结束。如何将自定义命令推送到bash的交互式会话中?我仍然需要正常运行.bashrc,因此我不能使用--rcfile
3 个解决方案
#1
10
My advice would be using a custom bashrc file with --rcfile
that sources your .bashrc, ex :
我的建议是使用自定义的bashrc文件和--rcfile来源你的.bashrc,例如:
alias admin=pagsh -c "bash --rcfile myrc"
别名admin = pagsh -c“bash --rcfile myrc”
myrc :
myrc:
source ~/.bashrc
kinit xtoth1@ADMIN.META
#2
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):
如果你需要的只是一行或两行,你可以使用“过程替换”[1]的酷bash功能在调用行上提供它。例如(在特定的python virtualenv中运行bash):
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.
[1]男人猛击并寻找“过程替代”。请注意,并非所有系统都支持此功能,但它应适用于所有Linux。
#3
1
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.)
可能有用。 (我没有工作的openafs环境来正确测试它。)
#1
10
My advice would be using a custom bashrc file with --rcfile
that sources your .bashrc, ex :
我的建议是使用自定义的bashrc文件和--rcfile来源你的.bashrc,例如:
alias admin=pagsh -c "bash --rcfile myrc"
别名admin = pagsh -c“bash --rcfile myrc”
myrc :
myrc:
source ~/.bashrc
kinit xtoth1@ADMIN.META
#2
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):
如果你需要的只是一行或两行,你可以使用“过程替换”[1]的酷bash功能在调用行上提供它。例如(在特定的python virtualenv中运行bash):
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.
[1]男人猛击并寻找“过程替代”。请注意,并非所有系统都支持此功能,但它应适用于所有Linux。
#3
1
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.)
可能有用。 (我没有工作的openafs环境来正确测试它。)