gpt4 book ai didi

java - Unix shell : Turn file with directory names to ':' separated classpath

转载 作者:行者123 更新时间:2023-11-29 07:19:55 24 4
gpt4 key购买 nike

我使用 Java5,我不想在类路径中指向每个 .jar 文件,所以我尝试编写小的 shell 脚本:

find $LIB_DIR -name '*.jar' -print > /tmp/classpath
CP=
cat /tmp/classpath | while read line
do
CP=$CP:$line
done
rm -f /tmp/classpath

但这不起作用 - $CP 变量为空。

因此 $CP 应该是单个字符串,路径由“:”分隔

有谁知道这里出了什么问题以及如何正确地将所有文件行连接到一个字符串?

最佳答案

您的 while 循环位于子 shell 中,因此不会将任何变量传递回主 shell。无论如何你都想做这样的事情:

CP=$(find $LIB_DIR -name '*.jar' -print | tr '\n' ':')

这将在一行中完成您想要的所有操作。

关于java - Unix shell : Turn file with directory names to ':' separated classpath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5898008/

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