gpt4 book ai didi

bash - 从 bash 文件中读取星号字符 (*)

转载 作者:行者123 更新时间:2023-11-29 09:22:33 25 4
gpt4 key购买 nike

我正在从 .txt 文件中提取行:说输入.txt

a
*
b

然后我正在阅读它:

#!/bin/bash
file=$1

ans=0
while read -r line || [[ -n "$line" ]]
do
echo $line
done < $file # passing the file

为此我得到以下输出

a
test main.py sic.sh
b

我的目录中的文件显示而不是 *

我想根据需要检测/读取 * 的 * 字符做出一些决定?

最佳答案

始终引用变量:

#!/bin/bash
file="$1"

ans=0
while read -r line || [[ -n "$line" ]]
do
echo "$line"
done < "$file" # passing the file

关于bash - 从 bash 文件中读取星号字符 (*),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53751907/

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