gpt4 book ai didi

linux - bash 引用传入的参数/变量

转载 作者:太空狗 更新时间:2023-10-29 11:42:42 24 4
gpt4 key购买 nike

如何引用管道传入的参数?

例如,如果你有如下代码test.sh

#!/bin/bash
echo $1

当您运行 ./test.sh abcd.txt 时,您将在屏幕上打印 abcd.txt。

但是当我尝试 ls *.txt | ./test.sh,我得到了所有 echo 空行。

最佳答案

您可以尝试使用 xargs:

find . -type f -name \*.txt -printf "%p\0" | xargs -0 -I xxx ./test.sh xxx 

关于linux - bash 引用传入的参数/变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36577752/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com