basically I am creating another SH file inside a SH file using vi editor and echo commands. here is the content of original SH file-
#!/bin/bash
echo "#!/bin/bash" > f1.sh
echo "echo "hello"" > f1.sh
f1 is the SH file I want to write into using echo commands but upon running the original file f1 file does not get #!bin/bash written into it it only has the echo "hello" command. I have tried writing the echo HASHBANG command as echo \#\!/bin/bash but that is not working as well. so how do u write #!bin/bash into another SH file using echo commands in vi editor?
>truncates the output file,>>appends to it. You're truncating the file on each echo, so only the text output by the last echo stays there. Also note that"echo "hello""is the same as"echo "hello, or"echo hello", the "inner" quotes won't be there in the output. Try something likeecho 'echo "hello"'. Or use a here-doc. – ilkkachu Aug 20 '21 at 11:52