在c shell别名中转义* char

时间:2010-07-15 09:37:02

标签: shell escaping

在cshell别名中转义* char

我想写一个C Shell Alias,它可以找到以模式开头的文件

即相当于 找 。 -name“pattern *”

myfind模式 应该在cmd以上,其中myfind是别名。如何在csh别名中转义*?

alias myfind'find。 -name!**'

2 个答案:

答案 0 :(得分:1)

你不需要逃避。这适用于 -

alias myfind "find . -name 'pattern*'"

答案 1 :(得分:0)

# the above post doesn't take into account \* arguments (including spaces in arguments)


# The original alias is useful for when you have time to type quotes or your
# arguments need to be regular expressions
alias ff 'find . -iname \!* -follow -print'

# alias fff (below) is of limited utility, because your arguments can't be regular
# expressions or enclosed in quotes.  It is useful for quick and dirty situations
# when you want to cut and paste things with spaces in them without using quotes.
# the combination of double quotes and single quotes here is very important.
# rules of thumb for "I hate typing quotes" style aliases:
#   enclose alias arguments \* in this construct:    '"\*"'
#   conversely, enclose wildcards in this construct: "'*'"
alias fff "find . -iname '*'"'"\!*"'"'*' -follow -print"

示例提示

/Projects/mbox/Installers/Mbox Studio Installer>alias ff
find . -iname !* -follow -print
/Projects/mbox/Installers/Mbox Studio Installer>ff "Mbox *.app"
./ROOT/Applications/Mbox Studio/Mbox Remote.app
./ROOT/Applications/Mbox Studio/Mbox Studio.app
./ROOT/Applications/Mbox Utilities/Mbox Controller.app
/Projects/mbox/Console>alias fff
find . -iname '*'"!*"'*' -follow -print
/Projects/mbox/Installers/Mbox Studio Installer>fff Mbox Studio
./NightlyBuild/DiskImages/Mbox Studio 3.6D3435.dmg
./NightlyBuild/DiskImages/Mbox Studio 3.6D3438.dmg
./ROOT/Applications/Mbox Studio
./ROOT/Applications/Mbox Studio/Mbox Studio.app