我正在尝试输出一个包含 MIPS 代码的文本文件,但是它一直在选择参数并且不会将它们写入文本文件。
代码:
function errorMessage() {
echo "You have entered the wrong amount of arguments. The default files will now be used"
echo '#input.txt' > input.txt
"add $s0 $s1 $s2" >> input.txt
"sub $s2 $t0 $t3" >> input.txt
"add $s0 $s1 $z2" >> input.txt
"lw $t1 8($t2)" >> input.txt
"addi $t3 $s0 -9" >> input.txt
"sw $s3 4($t0)" >> input.txt
"lw $t11 70000($s0)'" >> input.txt
}
结果:
#input.txt
add
sub
add
lw 8()
addi -9
sw 4()
lw 70000()
通过写入文件来创建文件的一种方法是使用所谓的“此处文档”。
#!/bin/bash
(
cat <<'EOF'
#input.txt
add $s0 $s1 $s2
sub $s2 $t0 $t3
add $s0 $s1 $z2
lw $t1 8($t2)
addi $t3 $s0 -9
sw $s3 4($t0)
lw $t11 70000($s0)
EOF
) > input.txt
这样做是需要的文字cat <<'EOF'
和EOF
并将其写入input.txt中。因为EOF
incat <<'EOF'
被引用,所以前面有 $ 的变量不会被视为 bash 变量,而是真正的文本。您可以将字符串替换EOF
为您想要的任何内容。您可以在此处了解有关 Here Documents 的更多信息:http : //tldp.org/LDP/abs/html/here-docs.html。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句