我有两个关于IFS
. 我知道更改内部字段分隔符IFS
会更改 bash 脚本迭代的内容。
那么,为什么数组的长度没有改变呢?
这是我的例子:
delimiter=$1
strings_to_find=$2
OIFS=$IFS
IFS=$delimiter
echo "the internal field separator is $IFS"
echo "length of strings_to_find is ${#strings_to_find[@]}"
for string in ${strings_to_find[@]}
do
echo "string is separated correctly and is $string"
done
IFS=$OIFS
但是为什么长度不受新 IFS 的影响?
我不明白的第二件事是如何使 IFS 影响输入参数。
假设我希望我的输入参数看起来像这样:
./executable_shell_script.sh first_arg:second_arg:third_arg
我想通过设置来解析输入IFS
参数:
。我该怎么做呢?设置 IFS 似乎没有做任何事情。我一定做错了……?
谢谢你。