Hi,
New user, first post, using Sublime Text 3 (Build 3047) on Linux Mint 13 LTS.
I have found that a technique I use a lot in my Bash scripts is breaking the syntax highlighting for:
Sublime Text 3 --> Menu --> View --> Syntax --> Shell Script (Bash)
The technique is called a here document and uses redirection within a script, the code below breaks the syntax highlighting unless the quote on line 9 is escaped, i.e. “For instance the single quote in this word’s example will break it.”
I use here documents a lot to display usage messages in my scripts. They work by redirecting to cat followed by a marker which below is ‘EndOfDisplayUsageMessage’. Everything after the initial marker will be output to the user’s terminal until the 2nd instance of the marker is encountered.
In ST the use of quotes in a here document can break the syntax highlighting. An odd number of ‘single’ or “double quotes” will cause this to happen. The code below breaks the syntax highlighting, images below that show a screen capture of it broken and unbroken when the single quote is escaped (unfortunately the escaped \ also gets output to the terminal).
#!/bin/bash
Display_Usage_Message()
{
cat << EndOfDisplayUsageMessage
Quotes in this 'here document' section can break the syntax highlighting.
An odd number of 'single' or "double quotes" will cause this to happen.
For instance the single quote in this word's example will break it.
EndOfDisplayUsageMessage
}
Example_Function_To_Show_Broken_Syntax_Highlighting()
{
local assignVar="Help Please"
echo "Syntax highlighting is broken :("
if "$canThisBeFixed" = "YesItCan" ]; then
echo "I'll be happy."
else
echo "I'll be sad."
fi
}
anotherVar="0"
for evenMore in "${supportForum@]}"; do
echo $evenMore
let 'anotherVar = anotherVar + 1'
done
Broken, single quote on line 9:
Not Broken, single quote escaped on line 9:
Is there any way for me to fix this? (Or even better a ST guru who can fix it for me in 2 mins?)
Perhaps treating “cat << Marker” as the start of a comment section and a 2nd instance of “Marker” as the end of the comment section?
I have here documents in literally dozens of my scripts.
Thanks.
P.S. Loving Sublime Text, it’s, well, sublime. ![]()