Alias for Command Parameter for Bash

bash的alias(别名)不直接支持$1,$2,$3,这样的命令行参数.

所以我们可以在/etc/bashrc中, 使用函数来替代.

(但是我不知道为什么貌似alias temp='echo $1', 这样会把对temp的参数打印出来, 需要进一步确认...)

 

Anyway, 比如像下面这样, 可以满足我的需求

ils() {
  find . -maxdepth 1 -iname \*$1\*
}

rls() {
  ls -al *$1*
}

 

BASH : Alias and Parameters

http://chinmaykamat.wordpress.com/2009/09/16/bash-alias-and-parameters/

 

Make bash alias that takes parameter?

http://stackoverflow.com/questions/7131670/make-bash-alias-that-takes-parameter

 

Pass Command Line Arguments To a Bash Alias Command

http://www.cyberciti.biz/faq/linux-unix-pass-argument-to-alias-command/

 

Alias, Setting command aliases

http://www.linuxhowtos.org/Tips%20and%20Tricks/command_aliases.htm

 

### Linux `which` Command Usage and Examples The `which` command in Linux serves as a tool to quickly locate the full path of executable files or scripts based on the directories listed within the environment variable PATH[^1]. The syntax for using this command is straightforward: ```bash which [options] [--] <COMMAND>... ``` For each parameter provided, it prints out the complete path of an executable file to standard output by searching through directories specified in the PATH environment variable with the same algorithm used by bash(1). To demonstrate how one might use the `which` command effectively, consider these examples: #### Example 1: Basic Use Case When looking up where Python's interpreter resides, ```bash $ which python3 /usr/bin/python3 ``` This indicates that `/usr/bin/python3` is the location of the Python 3 interpreter. #### Example 2: Handling Multiple Commands at Once If there are multiple commands whose locations need identifying simultaneously, ```bash $ which gcc g++ make /usr/bin/gcc /usr/bin/g++ /usr/bin/make ``` Each line represents the respective paths for GCC compiler (`gcc`), G++ compiler (`g++`), and Make utility (`make`) respectively. Regarding aliases and shell functions, while `which` does not directly support displaying their definitions due to its design focusing solely on executables found via $PATH searches, combining other utilities like `(alias; declare -f)` can help achieve similar outcomes conceptually. However, practical implementation often requires additional tools such as `grep`, `awk`, etc., since direct integration isn't supported natively by `which`. --related questions-- 1. How do you interpret the results when no output appears after running the `which` command? 2. Can the `which` command differentiate between different versions of installed software if both exist under separate directory structures? 3. What alternatives exist besides `which` for locating binaries more precisely including those defined as shell built-ins or aliases? 4. In what scenarios would someone prefer using `type` over `which` inside Bash shells?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值