Do special vi chars lose meaning if copied and pasted in script?
So I have my mutt installer script, looks ok, could be way more intuitive but anyhow, I copied code from VMplayer ubuntu terminal onto windows box notepad and back across and the ^@ (Enter) value was lost when copied back over.
This is an assignment which (because the lecturer is a bit of a lazy-s.o.b) will only be marked if the script works - concerned that the special chars will disappear...any advice appreciated. Code:
|
^@ isn't an enter value, it's actually a nul (or 0) byte. Internally, bash uses nul bytes to represent end-of-string, so you can't have it as the value of a string. Therefore, "^@" is the same as "".
Also, your indentation is inconsistent, and you have an extra "/" in your "#!". |
Copy/paste is an operation done using the display buffer - therefore it will copy what is displayed, which is not necessarily the same thing as what was typed.
|
Why are you copy-pasting it into Notepad? Just scp/ftp/email it or stick it on a USB drive. Copy/paste can lose a lot of info like jpollard said. Tabs turn into spaces, special characters turn into their displayed equivalents, etc.
|
Quote:
Thanks Code:
UBUNTU::./tester enter command enter ENTER Could it be wrong? |
Any time you start thinking 'special characters' in a shell script, you should be concerned. There aren't really any special characters required in a shell script, and anything that looks like one is more likely to give you grief than joy. When editing a script to run on a Linux host, edit the script on the Linux host. There are special characters in DOS/Windows editors called Carriage Returns which will give you grief.
And, since you're learning about Linux, you should embrace it in its full glory; use it, learn it, love it. |
Quote:
Code:
if [ "$entry" == "" ] ; then Code:
~/tmp$ x="foo" |
There is a utility called dos2unix that will convert DOS nl/return characters to the unix NL character. Scripts entered in notepad won't run until you fix the line endings. You will have the same problems with make files and name=value entries in config files.
You can also use the "od" command to examine control characters in text files. You can also use sed or vim to replace the end characters as well. |
Quote:
---------- Post added 02-20-13 at 11:49 AM ---------- Quote:
|
All times are GMT -5. The time now is 05:55 AM. |