Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash IFS(';\n';):通过find命令和for循环检测文件名时出现问题 #/bin/bash IFS='\n' 声明-i计数=0 AX=$(find*.iso-maxdepth 1-typef)#而是使用AX=“$(find*.iso-maxdepth 1-typef”? #A=“${AX%x}”_Bash_File_Ifs_Command Substitution - Fatal编程技术网

Bash IFS(';\n';):通过find命令和for循环检测文件名时出现问题 #/bin/bash IFS='\n' 声明-i计数=0 AX=$(find*.iso-maxdepth 1-typef)#而是使用AX=“$(find*.iso-maxdepth 1-typef”? #A=“${AX%x}”

Bash IFS(';\n';):通过find命令和for循环检测文件名时出现问题 #/bin/bash IFS='\n' 声明-i计数=0 AX=$(find*.iso-maxdepth 1-typef)#而是使用AX=“$(find*.iso-maxdepth 1-typef”? #A=“${AX%x}”,bash,file,ifs,command-substitution,Bash,File,Ifs,Command Substitution,命令替换是否正确?该变量不适用于for循环中的IFS\n,我不明白为什么会发生这种情况 for循环应该通过逐行处理find的输出来处理带有空格的文件名(这就是为什么我使用IFS\n) 该变量不适用于for循环中的IFS\n,我不适用 了解发生这种情况的原因 IFS='\n'不会将IFS设置为换行符,而是将IFS设置为文本字符串\n。如果要将IFS设置为换行符,请使用: #!/bin/bash IFS='\n' declare -i count=0 AX=$(find *.iso -maxd

命令替换是否正确?该变量不适用于for循环中的IFS\n,我不明白为什么会发生这种情况

for循环应该通过逐行处理find的输出来处理带有空格的文件名(这就是为什么我使用IFS\n)

该变量不适用于for循环中的IFS\n,我不适用 了解发生这种情况的原因

IFS='\n'
不会将
IFS
设置为换行符,而是将
IFS
设置为文本字符串
\n
。如果要将IFS设置为换行符,请使用:

#!/bin/bash

IFS='\n' 
declare -i count=0

AX=$(find *.iso -maxdepth 1 -type f) # Rather use AX="$(find *.iso -maxdepth 1 -type f"?
# A="${AX%x}" < Could I use this when applying "" to $() in AX? But it should already include newlines like this way. edit: I don't need the trailing newlines fix.

for iso in "$AX"
 do
  echo "Use "$iso"? [Y/N]?" # Outputs ALL files, IFS has no force somehow
  read choiceoffile
  shopt -s nocasematch
  case $choiceoffile in
  y ) echo "Using selected file.";;
  * ) continue;;
  esac
  # some sort of processing
done

我认为这里根本不需要
find
或第一个循环

这是你想要的吗

IFS=$'\n'

我还删除了无用的
n)
案例,因为默认案例处理得很好。

我现在已经修复了它。我已经放弃了for循环中变量的引用,在开始时修复了IFS的声明,并删除了不必要的管道。
这应该是解决空白问题的好办法
谢谢,现在我可以把它插入我的工作脚本了。我为什么要保留这些引语

for iso in *.iso
 do
  echo "Use $iso? [Y/N]?"
  read choiceoffile
  shopt -s nocasematch
  case $choiceoffile in
  y ) echo "Using selected file.";;
  * ) continue;;
  esac
  # some sort of processing
done

我不明白这里的问题。你能再解释一下吗?为什么在
.iso
文件上循环,然后使用
find
获取
.wbfs
文件?只循环这两个文件并对iso文件进行计数,对wbfs文件使用一个数组,然后只使用数组偏移量索引来获得所需的计数,这不是更容易吗<代码>大小写$image in*.iso)计数+=1;;*。wbfs)文件+=(“$image”);;esac然后是“${files[@]:$count}”?我的编辑速度不够快。在我的脚本的纯文本中都是$iso。代码之外的问题体应该有一些关于问题所在的额外解释。是否存在异常,或者输出/结果根本不是您所期望的?如果没有,为什么?这个代码不起作用怎么办?如果代码与您在本地拥有的或正在尝试执行的代码不准确,请编辑并修复它。正如Palu Macil更清楚地说的那样,请给我们更多的描述,说明您正在尝试做什么,以及此代码正在(和没有)发生什么。该
find
命令的目的是什么?您正在从循环中获取每个iso文件的计数,然后使用“查找”并将其输出限制为完全相同的计数?谢谢,这是除了引号之外的问题。如果您碰巧在某些文件名中有换行符,这也可能失败
#!/bin/bash

IFS=$'\n'   

AX=$(find *.wbfs -maxdepth 1 -type f )  

for wbfs in $AX  
 do  
  echo "Use "$wbfs"? [Y/N]?"  
  read choiceoffile  
  shopt -s nocasematch  
    case $choiceoffile in  
      y ) echo "Using selected file.";;  
      * ) continue;;  
    esac  
   # some sort of processing  
done