I'm trying to create a function that allows me to send two variables to it. My code:
#!/bin/bash
function myfunc{
cat > file.xml << EOFcat
<hostdev mode='subsystem' type='usb' managed='yes'>
<source>
<vendor id='0x$1'/>
<product id='0x$2'/>
</source>
</hostdev>
EOFcat
}
trigger="191a:8003";
vID=$(lsusb | grep $trigger | cut -d ':' -f2 | cut -d ' ' -f3)
pID=$(lsusb | grep $trigger | cut -d ':' -f3 | cut -d ' ' -f1)
echo "vID=$vID"
echo "pID=$pID"
myfunc ($vID $pID);
send me an error:
./script3.bash: line 3: syntax error near unexpected token `cat'
./script3.bash: line 3: `cat > file.xml << EOFcat'
If I'm not mistaken, that means I can't use 'cat' inside function.
So, the question arises: is it possible to write a function that will allow you to create an XML file with the passed parameters inside?