Can't reference parameter in Bash
I want to put TextA at the beginning of TextB with
cat TextA A TextB
The problem is that I don't know how to refer to the first and second parameters: TextA and TextB in the following script called A:
#!/bin/bash
cat TextA > m1
cat TextB > m2
cat m1 m2 > TextB
where m1 and m2 are temporary files.
How can you link to two files in a shell script?
+1
a source to share
6 answers
I would do the following:
#!/bin/bash
if [ $# -ne 2 ]
then
echo "Prepend file with copyright notice"
echo "Usage: `basename $0` <copyright-file> <mainfile>"
exit 1
fi
copyright=$1
mainfile=$2
cat $mainfile > /tmp/m.$$
cat $copyright /tmp/m.$$ > $mainfile
#cleanup temporary files
rm /tmp/m.$$ /tmp/m2.$$
+1
a source to share