Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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
Shell 普通字符串和字符串from变量之间的区别是什么_Shell_Eslint - Fatal编程技术网

Shell 普通字符串和字符串from变量之间的区别是什么

Shell 普通字符串和字符串from变量之间的区别是什么,shell,eslint,Shell,Eslint,我正在尝试编写简单的shell脚本,它将在许多文件上运行linter。我将所有文件名存储在一个长字符串中,然后还从中删除了所有可能的/n符号。然后,我运行linter,使用这些文件的名称进行硬编码,并从变量中获取。对于硬编码的路径,我的linter可以工作,并且可以找到那个些文件,但对于存储在变量中的这些文件的路径,它不能 以下是我尝试过的: #/垃圾箱/垃圾箱 所有_文件_to_commit=$(git diff--仅名称--缓存) 以_ts=“.\.ts$”结尾 以_scss=“.\.scs

我正在尝试编写简单的
shell
脚本,它将在许多文件上运行linter。我将所有文件名存储在一个长字符串中,然后还从中删除了所有可能的
/n
符号。然后,我运行linter,使用这些文件的名称进行硬编码,并从变量中获取。对于硬编码的路径,我的linter可以工作,并且可以找到那个些文件,但对于存储在变量中的这些文件的路径,它不能

以下是我尝试过的:

#/垃圾箱/垃圾箱
所有_文件_to_commit=$(git diff--仅名称--缓存)
以_ts=“.\.ts$”结尾
以_scss=“.\.scss$”结尾
所有_ts_文件=“”
所有scss文件=“”
对于$all_files_to_commit中的文件
做
如果echo“$file”| grep“$ends_with_ts”;然后
all_ts_files=“${all_ts_files}${file}”
fi
如果echo“$file”| grep“$以_scss结尾”;然后
all_scss_files=“${all_scss_files}${file}”
fi
完成
all_ts_files=$(echo“$all_ts_files”| tr-d”\n)
回显“一个字符串中的所有文件”
echo“$all\u ts\u文件”
./node_modules/.bin/eslint src/components/List/List.ts src/views/Calculator/Calculator.ts—安静
./node_modules/.bin/eslint“$all_ts_文件”--安静
你知道为什么这些路径会不同吗?我该如何解决这个问题

我还尝试了这个脚本,没有删除
\n
符号的行

输出:

All files in one string
src/components/List/List.ts src/views/Calculator/Calculator.ts 

/home/kaczor6418/Desktop/projects/expressions-calculator/src/components/List/List.ts
  24:9  error  Delete `·············`  prettier/prettier

/home/kaczor6418/Desktop/projects/expressions-calculator/src/views/Calculator/Calculator.ts
  53:9  error  Unexpected var, use let or const instead  no-var
  54:9  error  Delete `············`                     prettier/prettier

✖ 3 problems (3 errors, 0 warnings)
  3 errors and 0 warnings potentially fixable with the `--fix` option.


Oops! Something went wrong! :(

ESLint: 7.11.0

No files matching the pattern "src/components/List/List.ts src/views/Calculator/Calculator.ts " were found.
Please check for typing mistakes in the pattern.
引用

./node_modules/.bin/eslint "$all_ts_files" --quiet
找到的文件名连接到一个带有空格的文件名中。 字符串
src/components/List/List.ts src/views/Calculator/Calculator.ts
不代表文件(您没有名为
List.ts src
的目录)。 使用给定的文件名,可以删除引号:

./node_modules/.bin/eslint $all_ts_files --quiet
从文件名列表生成字符串时,您无法看到空格(或换行符)何时是文件名的一部分。
在您的示例中,您可以尝试使用数组:

all_files_to_commit=($(git diff --name-only --cached))
# change code here when you want to use arrays
./node_modules/.bin/eslint ${all_ts_files[@]} --quiet
或者使用类似

./node_modules/.bin/eslint $(git diff --name-only --cached | grep ts$) --quiet
您可以使用

./node_modules/.bin/eslint $(git diff --name-only --cached | sed -n '/ts$/ s/.*/"&"/p' ) --quiet