I want to run this bash command :
#!/bin/bash rep="*" for f in `ls -R`$rep; do d='git log '$f'| wc -l' c=$d echo $c done
how to excute a command
git log myFile | wc -l from bash ?
ps : this command will return a number :
git log myFile | wc -l
If you want to execute a command and get the output use the line below
In your script you have to change two two things. I have the correct script below
#!/bin/bash rep="*" for f in `ls -R $rep`; do d=`git log $f| wc -l` c=$d echo $c done
Edit: The original correction is changing the quotes to backticks to make the output reach the d variable. In addition, the $rep should be inside the backticks with the ls, otherwise it will add the * at the end of the last file name processed.
I think you want to do:
Notice the double quotes instead of the single ones around git command.
A smaller solution could be to use:
As far as i know the command :
Will show all the revision histories. If that is true, i guess you are trying to store the contents inside a file called myfile and then you want to count the no of lines in the file.
If this is what you want, first you can save the history in this way:
Now you need to find the no of lines using wc -l and store it a file called nOfLines.txt
So you have to do this :
Then store the content of this file inside a variable called gitVar.
You can see whether this is working properly using this command :
Just bundle the whole thing inside a script called "myCommand.sh", give it permssions using chmod a+x and run the script from the terminal like a command.
Hope this helps you .
Do not parse the output of
To get the output of
Note that you need double quotes around the variable name. Always use double quotes around variable and command substitutions:
The use of
Since bash ≥4, you don't need to use