My team uses CVS for revision control.I need to develop a shell script which extracts the content from a file and does a CVS tag to all .txt files(also the text files present in the sub-directories of the current direcotry) with that content. The file from which the content is extracted ,the script ,both are present in the same directory.
I tried running the script :
#!bin/bash
return_content(){
content=$(cat file1)
echo $content
}
find . -name "*.txt" -type f -print0|grep - v CVS|xargs -0 cvs tag $content
file1=> the file from where the content is extracted "abc"=> content inside file1
Output:
abc
find: paths must precede expression
Usage: find [path...] [expression]
cvs tag: in directory
cvs [tag aborted]: there is no version here; run 'cvs checkout' first
I cannot figure out the problem. Please help
There are a few problems with the script.
1) The shebang line is missing the root /. You have #!bin/bash
and it should be #!/bin/bash
2) the -v
option to grep has a space between the - and the v (and it shouldn't)
3) You don't actually call the return_content function in the last line - you refer to a variable inside the function. Perhaps the last line should look like:
find . -name "*.txt" -type f -print0|grep -v CVS|\
xargs -0 cvs tag $( return_content )
4) even after fixing all that, you may find that the grep complains because the print0 is passing it binary data (there are embedded nulls due to the -print0), and grep is expecting text. You can use more arguments to the find command to perform the function of the grep command and cut grep out, like this:
find . -type d -name CVS -prune -o -type f -name "*.txt" -print0 |\
xargs -0 cvs tag $( return_content )
find will recurse through all the entries in the current directory (and below), discarding anything that is a directory named CVS or below, and of the rest it will choose only files named *.txt.
I tested my version of that line with:
find . -type d -name CVS -prune -o -type f -name "*.txt" -print0 |\
xargs -t -0 echo ls -la
I created a couple of files with spaces in the names and .txt extensions in the directory so the script would show results:
bjb@spidy:~/junk/find$ find . -type d -name CVS -prune -o \
-type f -name "*.txt" -print0 | xargs -t -0 ls -la
ls -la ./one two.txt ./three four.txt
-rw-r--r-- 1 bjb bjb 0 Jun 27 00:44 ./one two.txt
-rw-r--r-- 1 bjb bjb 0 Jun 27 00:45 ./three four.txt
bjb@spidy:~/junk/find$
The -t argument makes xargs show the command it is about to run. I used ls -la
instead of cvs tag
- it should work similarly for cvs.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.