say i have a script that says
cat > resultofsample.sh
#!/bin/bash
codes
but how can i exit it from here and save it?
say i have a script that says
cat > resultofsample.sh
#!/bin/bash
codes
but how can i exit it from here and save it?
in vi mode, type the fllowing:
:wq!
Type CTRL+D to signal EOF.
Press Ctrl+d to save and exit. This should be done in the new line i.e line after the word codes
cat > resultofsample.sh
#!/bin/bash
codes
Ctrl+d
seems not working. i'm stuck to an empty shell without a prompt.
lets say i have this whole script.
the script must create a script named resultofsample.sh
which supossedly have these codes
it did create the script but its empty.
Did you type 'crtl + d' or did you press 'D' key while holding down the 'Ctrl' key ? It should be the latter.
Im not sure how to execute Ctrl + d within a script. But could try as below
#!/bin/bash
ls -l
#cat > resultofsample.sh
echo "#!/bin/bash" >resultofsample.sh
echo "codes" >>resultofsample.sh
thanks all. thanks mike. it now works
Instead of using multiple echo's, try using here document.
cat > resultofsample.sh <<EOF
#!/bin/bash
# codes
EOF