linux - 在 linux 中使用 * 命令运行文件

标签 linux bash scripting

<分区>

假设我希望运行目录中的所有脚本。如果我执行 ./*.sh,它们将按什么顺序运行?

目录: 1.sh 2.sh 3.sh

最佳答案

要运行所有脚本,您必须单独运行它们:

for f in ./*; do
    "$f"
done

该模式将生成一个按字母顺序排序的脚本列表,其中“字母顺序”由您当前的语言环境定义。

你的尝试:

 ./*

将扩展为匹配文件的列表,然后 shell 会将其视为单个命令。第一个脚本将被执行,其余脚本名称作为参数传递给第一个脚本。

关于linux - 在 linux 中使用 * 命令运行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21386017/

相关文章:

linux - perl脚本中的chown命令用法

linux - 构建将内容附加到特定文件的脚本的最简单方法,用于此类任务的 Windows 或 Linux?

python - 文本文件之间的交集

filter - elasticsearch - 将嵌套字段与文档中的另一个字段进行比较

linux - 当另一个进程在 Linux 中结束时终止后台进程

linux - 为什么 ld 不支持 '-rpath-link' 选项?

linux - 状态错误 : no such file or directory while building Docker from a custom image with Docker build command

bash - jq : command not found in GitLab CI file

linux - 带/不带引号和单引号/双引号的 bash 字符串

bash - 将数据存储在数组中(bash 脚本)