bash脚本的一部分是访问一系列文件夹:
#lsit of folders
locations=("/Volumes/Israel\ Hernandez/Quantitative\ Data/Microglia\ data/3\ month/Mutant/314a"
"/Volumes/Israel\ Hernandez/Quantitative\ Data/Microglia\ data/3\ month/Mutant/314b"
"/Volumes/Israel\ Hernandez/Quantitative\ Data/Microglia\ data/3\ month/Mutant/314c")
for i in "${locations[@]}"
do (
#change to directory
cd "$i"
#convert tiff to png然而,当我收到错误时:
/Users/luna/Documents/Ethan/scripts/microglia.sh: line 16: cd: /Volumes/Israel\ Hernandez/Quantitative\ Data/Microglia\ data/3\ month/Mutant/314a/: No such file or directory我试着把cd放进终端上的文件夹里,结果真的成功了。为什么它不能在shell脚本中工作呢?
发布于 2016-11-03 01:37:10
您不需要反斜杠在空格之前转义,因为空格已经在一个双引号字符串中。你的话是正确的-高兴!删除""字符串中的反斜杠,您应该被设置。
发布于 2016-11-03 01:40:07
错误很明显:“没有这样的文件或目录!”您可以在终端上执行命令"cd /Volumes/以色列\ Hernandez/Quantitative\ Data/Microglia\ data/3个月/Mutant/314 a/“。
如果错误是“没有这样的文件或目录!”,您应该仔细检查路径。不要怀疑脚本解析器本身!只是怀疑您的代码!
发布于 2016-11-03 01:44:03
在执行cd命令之前,您应该处理$i中的转义空间。下面是代码,希望它有所帮助。
#lsit of folders
locations=("/Volumes/Israel\ Hernandez/Quantitative\ Data/Microglia\ data/3\ month/Mutant/314a"
"/Volumes/Israel\ Hernandez/Quantitative\ Data/Microglia\ data/3\ month/Mutant/314b"
"/Volumes/Israel\ Hernandez/Quantitative\ Data/Microglia\ data/3\ month/Mutant/314c")
for i in "${locations[@]}"
do (
#reverse esxape chars such space in you code
i="echo \$\'"$(echo $i|sed -e 's|\\|\\\\|g')"\'"
i=$(eval "echo $(eval $i)")
i=$(eval "echo $(eval $i)")
#change to directory
cd "$i"
#convert tiff to pnghttps://stackoverflow.com/questions/40392412
复制相似问题