庆典:如何拦截命令行,做基于内容的各种操作? [英] bash: How to intercept command line and do various actions based on the contents?
问题描述
我想知道解决以下问题。
I would like to know a solution to the following problem.
问题:当我在命令行中输入一个数字/串,我应该能够跨preT它在我自己的路,做基于字符串的例如内容的任何行动如果是然后一个数字DO动作,否则做动作2等。
Problem: When I enter a number/string on command line, I should be able to interpret it in my own way, and do any action based on the contents of the string e.g. if it is a number then do action1, else do action 2, etc.
例如:
$ 85049
[ This should do 'cd /dir1/dir2/../85049' ]
我不能让一个别名这一点,因为我可以输入任何大的数字。
I cannot make an alias for this, as I can enter any big number.
任何想法,如何通过bash中实现这一功能?
Any ideas, how to achieve this functionality via bash?
推荐答案
您可以使用 command_not_found_handle
功能。
的http://www.gnu.org/software/bash/manual/bashref.html#Command-Search-and-Execution
我不认为这是一个很好的主意,但并建议你重新考虑原来的premise。
I don't think that's a very good idea though and would suggest that you rethink your original premise.
这篇关于庆典:如何拦截命令行,做基于内容的各种操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!