Comments (5)
问题2已经使用了转义符去转义$和'
from zshguide.
a=1234
echo ${#a}
4
echo $#{a}
0{a}
echo
26961
echo ${${${#a}}}
4
不是很懂那个26961怎么来的。。
from zshguide.
echo $#{a}
0{a}
这个用法已经错了,$#
是命令行传入参数的数量。 ${$#{a}}
这种用法就没意义了,打出 26961
是因为最后解析成了 $$
,也就是当前进程的 pid。
Zsh 的语法很复杂,一定要按照规则写,不然很可能出现奇怪的问题。
from zshguide.
1.a=$(grep a test)
echo ${(t)a}
得到: scalar
但:echo ${(t)$(grep a test)}
就什么输出都没有
你的 test 文件内容是什么?如果只有 scalar,我这里是有输出的。
2.test文件有一行是以$为开头的
echo ${"$(<test)"[(fr)\$*]}
结果输出是没问题的
但当我把$换成单引号
echo ${"$(<test)"[(fr)\‘*]}
结果就是什么输出也没有,明明文件里有这一行,但是却没有匹配成功
可以用 echo "${"$(<test)"[(fr)'*]}"
,但这个用法确实对特殊符号不友好,可以先把符号放变量里,再把变量传进来,比如:
% x="'"
% echo ${"$(<test)"[(fr)$x*]}
这样就不用和奇怪的转义较劲了。
from zshguide.
3.还有就是那个(r)变量修饰符,我花了老大的劲才试出来它原来是不支持正则的,支持的是通配符
回想一开始学python的时候,根本没有这么多事。。
Zsh 为了支持各种各样奇怪的语法(来自 Bash、Perl 或者自创),加上复杂的转义规则,有些地方确实难以捉摸,也不排除存在 bug 的可能。平时使用的话没必要特别关注某些晦涩语法,即使功能正常,代码也不好理解。
from zshguide.
Related Issues (6)
- 求教一个问题,如何能按行处理一个文件,并且能支持空行? HOT 5
- 第一章,always语句测试与预期不符 HOT 2
- 第十篇-文件查找和批量处理)中的通配符的修饰符的F的含义 HOT 1
- 注意:不回答任何 zsh 相关问题 HOT 2
- [typo] str +="\n$str" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zshguide.