Linux 是一个内核。您显示的脚本是一个 shell 脚本。
在 Bourne shell 系列中,所有原子变量都是字符串。 (在 Bash / ksh / etc 中也有数组,它们是字符串的集合。)
要去掉字符串两边的引号,试试这个parameter expansions序列:
value=${value%\"}
value=${value#\"}
使用 shell 内置程序将比使用外部进程快得多,但如果您在询问之前已经用谷歌搜索过,这些中的每一个都应该是相当明显的:
value=$(echo "$value" | tr -d '"') # discards " everywhere
value=$(sed 's/^"\(.*\)"$/\1/' <<<"$value") # Bash specific <<<here string
value=$(awk -v val="$value" 'BEGIN { sub(/^"/, "", val); sub(/"$/, "", val); print val }')
您的循环将读取并丢弃文件中的所有值,然后处理文件最后一行中的任何内容。我猜你想处理 inside 循环中的每个值?
while IFS="" read -r line; do
result=${line%\"}
result=${result#\"}
[ $result -gt 0 ] && { echo "Failed" >&2; exit 1; }
done < File.csv
(注意 IFS="" 和 read -r,并将错误消息打印到标准错误而不是标准输出)但是 很多 更好的解决方案是为此使用 Awk(shell 的 while read -r是horribly inefficient and usually wrong);
awk '{ sub(/^"/, ""); sub(/"$/, "");
if (0+$0 > 1) { print "Failed" >>"/dev/stderr"; exit 1 } }' File.csv