creating a file dynamically
I want to save a few lines as a file etl.xml I tried the following but it is not working for obvious reasons.
cat etl.xml << myscript
<etl>
<connection id="in" driver="xpath" url="/home/test.xml"/>
<query connection-id="in">
/TXNEXP/AUTHADV
<script connection-id="db">
</script>
</query>
</etl>开发者_运维技巧;
myscript
Just need one more character:
508 $ cat xmlhere.sh
#!/bin/bash
cat > etl.xml << myscript
<etl>
<connection id="in" driver="xpath" url="/home/XXX/WAVtxnexp20101125.xml"/>
<query connection-id="in">
/TXNEXP/AUTHADV
<script connection-id="db">
</script>
</query>
</etl>
myscript
This is a "here document".
I assume you want to use some end marker. In that case, the syntax is "cat > outputfile << end_marker":
$ cat > etl.xml << EOF
here I write the file contents
EOF
If, instead, you want to append the line "myscript" to etl.xml, then:
$ echo myscript >> etl.xml
You can do it like this:
cat myscript > etl.xml
or
echo myscript > etl.xml
The flow is:
origin > destiny
Overwrite the contents >
Append >>
精彩评论