标签: yash

检查变量是像 shell 一样的 Bourne 数组吗?

在支持数组变量的类似 Bourne 的 shell 中,我们可以使用一些解析来检查变量是否为数组。

下面的所有命令都是在运行后运行的a=(1 2 3)

zsh

$ declare -p a
typeset -a a
a=( 1 2 3 )
Run Code Online (Sandbox Code Playgroud)

bash

$ declare -p a
declare -a a='([0]="1" [1]="2" [2]="3")'
Run Code Online (Sandbox Code Playgroud)

ksh93

$ typeset -p a
typeset -a a=(1 2 3)
Run Code Online (Sandbox Code Playgroud)

pdksh 及其衍生物:

$ typeset -p a
set -A a
typeset a[0]=1
typeset a[1]=2
typeset a[2]=3
Run Code Online (Sandbox Code Playgroud)

yash

$ typeset -p a
a=('1' '2' '3')
typeset a
Run Code Online (Sandbox Code Playgroud)

一个例子bash

if declare -p var 2>/dev/null …
Run Code Online (Sandbox Code Playgroud)

shell bash ksh zsh yash

16
推荐指数
3
解决办法
4590
查看次数

对yash shell中的printf是否是内置命令有点困惑

yash外壳有一个printf内置的,根据其说明书

但是,这是我在yash具有默认配置的shell 中看到的:

$ command -v printf
/usr/bin/printf
$ type printf
printf: a regular built-in at /usr/bin/printf
Run Code Online (Sandbox Code Playgroud)

printf这个shell中是否内置了?结果与许多其他假定的内置实用程序类似,这些实用程序也可用作外部命令。

作为对比,在pdkshksh在OpenBSD,这里printf不是内置的):

$ command -v printf
/usr/bin/printf
$ type printf
printf is /usr/bin/printf
Run Code Online (Sandbox Code Playgroud)

并在bash(其中printf 内置的):

$ command -v printf
printf
$ type printf
printf is a shell builtin
Run Code Online (Sandbox Code Playgroud)

posix shell-builtin printf yash

15
推荐指数
2
解决办法
1056
查看次数

标签 统计

yash ×2

bash ×1

ksh ×1

posix ×1

printf ×1

shell ×1

shell-builtin ×1

zsh ×1