linux - run cat command for all the files in the directory given in argument of the script file and out put with the name given as second argument -
i run following code concatenating files in directory given argument script file in bash
for in $* cat $* > /home/christy/documents/filetest/catted.txt done
this produce error
cat: /home/christy/documents/filetest/catted.txt: input file output file
i think there @ least 4 things wrong script....
firstly, loop set value of i
name of each file in succession, want use i
inside loop, this:
for in $* cat "$i" ....somewhere done
secondly, if use >
redirection, each file land exactly on top of previous one, should use >>
redirection append current file end of previous 1 this
for in $* cat "$i" >> ...somewhere done
thirdly, think should use double-quoted "$@"
command-line arguments, rather plain $*
for in "$@" ...
fourthly, can achieve exact effect think want simpler command:
cat "$@" > /home/christy/documents/filetest/catted.txt
Comments
Post a Comment