V
V
Vladislav Khvostov2016-10-04 17:18:51
linux
Vladislav Khvostov, 2016-10-04 17:18:51

How to forward arguments to the next pipe?

There is a program called like this:
```
cat some.js | eslint --stdin --stdin-filename=some.js
```
takes the contents of a file as input, and it also has a parameter that takes a filename. (--stdin-filename=some.js) is needed for correct output.
How do I forward an argument from one part (in this case, some.js) to the next part and substitute in the --stdin-filename parameter?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RPG, 2016-10-04
@vlakhvo

В данном конкретном случае можно вызвать просто: eslint yourfile.js
Пробросить аргумент, если я правильно понял, можно с помощью переменной:

file=some.js
eslint --stdin --stdin-filename="$file" < "$file"

Или обернуть в функцию:
myeslint() {
eslint --stdin --stdin-filename="$1" < "$1"
}
myeslint some.js

Вместо cat лучше использовать перенаправление ввода (<).
UPD. Не заметил комментария.
Ну и напоследок кунг-фу:
git diff --cached --name-only | xargs -I{} bash -c "cat {} | eslint --stdin --stdin-filename={}"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question