-5

I have a versioning command and we have to manually run it with all the changed files.

Is it possible to pass the changed and added files to another command as argument?

I have tried solutions mentioned in this link: is it possible to `git status` only modified files?, but its not working.

For sample I have made a dummy command:

function notify(){
    echo "*****************************************************************"
    echo $1
    echo "*****************************************************************"
}

And I try to use it as:

git status -s | notify

git ls-files -m | notify

enter image description here

Is there a way to send individual file path to such command?


Edit 1:

As rightly pointed by mallaudin, I was missing xargs. But adding that now throws another error.

xargs: notify: No such file or directory

Community
  • 1
  • 1
Rajesh
  • 24,354
  • 5
  • 48
  • 79

2 Answers2

4

You can use xargs

git ls-files -m | xargs notify

From this question

xargs takes an executable as an argument (including custom scripts) rather than a function defined in the environment.

Either move your code to a script or use xargs to pass arguments to an external command.

You can move your function's code to a separate bash file e.g. notify.bash and use it like

git ls-files -m | xargs notify.bash
Community
  • 1
  • 1
mallaudin
  • 4,744
  • 3
  • 36
  • 68
  • 1
    Unfortunately it didn't work. It throws following error: `xargs: notify: No such file or directory`. Still you are correct – Rajesh Mar 30 '17 at 12:54
0

Pipe output to bash function this can help you.

function notify(){
    echo "*****************************************************************"
    read foo
    echo "*****************************************************************"
}
Community
  • 1
  • 1
utkusonmez
  • 1,486
  • 15
  • 22