Question

I am creating a basic script in vi. First, I typed the code in Notepad++ and when I was ready I copied it in vi. At some point, the colors change completly. For example the comment becomes purple.

Searched for sintax errors and color interpretation but no succes. And also the script seems to work. Does anyone know what happened?

#find system and last database partition date
system_date=`date '+%m%d%Y'`
database_date=$(find_last_partition_date)

# testing colour ...OK

#convert system and last database partition dates to unix time

# testing colour ...OK
unix_system_date=`date -d $(sed -r 's#(..)(..)(....)#\1/\2/\3#' <<<$system_date) +%s`

#testing colour ...purple not blue

unix_database_date=`date -d $(sed -r 's#(..)(..)(....)#\1/\2/\3#' <<<$database_date) +%s`
#testing colour

#compare them to determine the initial parameter
if (( unix_database_date > unix_system_date )); then
        start_date=`date +"%m%d%Y" -d "${database_date:4}${database_date:0:4} + 1 day"`
else
        start_date=`date '+%m%d%Y' -d "$actual_date+2 days"`
fi


cd /opt/data/apps/utils


################################################ 1st cycle ################################################

vi colors

Was it helpful?

Solution

Vim automatically looks at the file extension as well as the file content to determine a syntax highlighting scheme. Make sure your bash script has a ".sh" at the end and starts with a "#!/usr/bin/sh"

You can check the filetype vim is using for syntax highlighting with

:set filetype

or change it to bash for a session with

:set filetype=sh
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top