Code Monkey home page Code Monkey logo

Comments (5)

tztnuaji avatar tztnuaji commented on September 2, 2024

问题2已经使用了转义符去转义$和'

from zshguide.

tztnuaji avatar tztnuaji commented on September 2, 2024

a=1234
echo ${#a}
4

echo $#{a}
0{a}

echo ${$#{a}}
26961

echo ${${${#a}}}
4

不是很懂那个26961怎么来的。。

from zshguide.

goreliu avatar goreliu commented on September 2, 2024
echo $#{a}
0{a}

这个用法已经错了,$# 是命令行传入参数的数量。 ${$#{a}} 这种用法就没意义了,打出 26961 是因为最后解析成了 $$,也就是当前进程的 pid。

Zsh 的语法很复杂,一定要按照规则写,不然很可能出现奇怪的问题。

from zshguide.

goreliu avatar goreliu commented on September 2, 2024
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.

goreliu avatar goreliu commented on September 2, 2024
3.还有就是那个(r)变量修饰符,我花了老大的劲才试出来它原来是不支持正则的,支持的是通配符
回想一开始学python的时候,根本没有这么多事。。

Zsh 为了支持各种各样奇怪的语法(来自 Bash、Perl 或者自创),加上复杂的转义规则,有些地方确实难以捉摸,也不排除存在 bug 的可能。平时使用的话没必要特别关注某些晦涩语法,即使功能正常,代码也不好理解。

from zshguide.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.