Originally Posted by suicidaleggroll
Sure, what problems are you facing? The shebang being repeated doesn't matter, because "#" is a comment in a bash script. It only has the special meaning of a "shebang" when it's the first line in the file.
Here's a self-replicating script:
rm -f newscript.sh
while read line; do
echo "$line" >> newscript.sh
done < $0
chmod +x newscript.sh
Ok this will probably make me crazy but will try to work through it, just want to get my head around the logic and commands - so I want to create a file called "newtest" which when ./newtest runs will create a script called "newtest2" which chmods and runs it to echo "it worked".
Question 1 - how to create a script to create and write (vi) to a new script? (confused)
Question 2 - If ctl-v followed by escape is correct - then i to insert ane ctl-v x: to save and exit, then chmod and run - Is this order even correct yet alone the syntax???
Question 3 - Is it worth it? should i just keep 5/6 separate scripts???
echo "it workd"
chmod 755 newtest2