After editing / copying the original bash script which was in colors I now have plain black / white nano editor text in the file. It's no biggie, just like to find out how it possibly happen and if I can "recover" back to color text. Thanks
nano uses file extensions and shebang (
#!) lines to determine how to highlight a file.
Save the file in
nano with the .sh extension as well as having
#!/bin/bash in the first line of the file/script and it'll autoapply the syntax highlighting.
nano filename.sh would have auto-enabled the highlighting as well, since it knows the filename you're going to be writing to.
Can you explain a bit more about the source of your script, was it copied from another editor or webpage, was it in colour there?
The colour is normally as a result of syntax highlighting which is not a property of the text it's self it's just pain text, the highlighting occurs because the text editor of choice has a system which understands and highlights specific words / characters according to the category of item, e.g. variable, function etc. for the programming language being used. This is often detected via file extension e.g.
.sh for a shell/bash script and or the initial shebang line e.g.
#!/bin/bash which would indicate that the interpreter is the bash binary in the
/bin directory, which should cause an editor to use syntax highlighting appropriate for the bash shell language.
It's not strictly true that you need to save the file first before syntax highlighting will work, this is only correct if you run nano without specifying a file name to write to, so if you type
nano scriptname.sh it will highlight right away before you've written out the file. In this case it has detected the language from your the
.sh file extension.
If you're having issue with syntax highlighting in nano it can be enabled by editing your
~/.nanorc configuration file as explained here, with further relevant documentation available on the GNU Nano homepage.