Bash:保存并打印数组中的参数

标签 bash command-line-arguments

如何将 bash 脚本中的所有参数保存到数组中并单独打印?

最佳答案

初始化数组:

ARGS=("$@")              # "$@" gives the arguments passed to the script
ARGS=(arg1 arg2 arg3)    # or fill the array out yourself

显示数组项:

for ARG in "${ARGS[@]}"; do
    printf '%s\n' "$ARG"
done

关于Bash:保存并打印数组中的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11711461/

相关文章:

Linux:更新基于前缀的文件夹中已有的数百万张图像的目录结构

linux - 如何在 Linux 上自动进行 FTP 文件传输?

python - 解析命令行参数的最佳方法是什么?

使用 C 的参数输入来转换问题

linux - 如何判断变量中是否已定义标志?

angular - 如何在预提交时运行 ng lint 并检测错误?

c# - 在 Powershell 中使用参数调用 Invoke-Expression

c++ - 未存储命令行参数(使用 boost)

bash - 如何base64编码/dev/random或/dev/urandom?

terminal - Grunt - 从命令行传递文件名变量