相关疑难解决方法(0)

zsh中的变量扩展与bash中的变量不同

以下是我想要说明的简单测试用例.

在bash,

# define the function f
f () { ls $args; }

# Runs the command `ls`
f

# Runs the fommand `ls -a`
args="-a"
f

# Runs the command `ls -a -l`
args="-a -l"
f
Run Code Online (Sandbox Code Playgroud)

但在zsh

# define the function f
f () { ls $args }

# Runs the command `ls`
f

# Runs the fommand `ls -a`
args="-a"
f

# I expect it to run `ls -a -l`, instead it gives me an error
args="-a -l" …
Run Code Online (Sandbox Code Playgroud)

bash shell zsh

13
推荐指数
1
解决办法
5148
查看次数

标签 统计

bash ×1

shell ×1

zsh ×1