-
Notifications
You must be signed in to change notification settings - Fork 871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error using Sublime Text to create shell scripts #2365
Comments
I assume you are talking about Windows Sublime Text using interop in "bash mode". If so, this is probably a variation of #2318. Basically same as this. Check your end-of-line convention in Sublime. You want explicit Unix style. I speculate in your "... continue to add code to the file ... runs fine" scenario, Sublime has kicked in some kind of auto-detection of Unix EOL convention and goes with the flow thereon. For a while now I have been wanting to share this old (and long addressed) VSCode github post for comedic value. |
Thanks for the reply and yes, I do mean Windows Sublime Text. When I referred to "bash mode", I was referring to Sublime's default syntax for the session I was working in. I certainly considered end-of-line conventions in Sublime so I tried different things to test for that but I could not identify it. The strange thing is that it only happened when writing the first conditional statement. If I do that in vi on the command line, I can reopen the file and write many other IF's without an issue. You might be right about the Sublime's potential "auto-detection of Unix EOL conventions" but I would have thought I would see that with other statements. I will take a look at #2318. Thanks. |
"It's complicated". In Bash (as a scripting language), carriage return is syntactically correct in some contexts. This is a perfectly legal bash script:
That script is outputting invisible carriage returns to At the end of the day, Cygwin's |
I think even guido once said that if he were to change one thing about python, he would change this part. :) |
The behaviour here was explained by CRLF problems that would manifest on Real Linux. |
This is a strange one.
When I create a new bash script using Sublime Text (in Bash Shell mode), it works fine until I create a conditional statement, in this case and IF statement.
The script will not work unless I create the first IF condition using vi on the command line. If I write the first conditional statement using vi on the command line, I can open the script in Sublime Text and write other conditional statements and it works fine.
If I write the following using Sublime text:
#!/bin/bash
echo "checking for the item file"
item="item.txt"
if [ -r $item ]
then
echo "The item file exists and is readable"
else
echo "The item file does not exist or is not readable"
fi_
The echo and variable assignment will run but when I add the IF statement, I get the following error:
user@machine:/mnt/c/scripts$ ./item_file.sh
checking for the item file
./item_file.sh: line 9: syntax error near unexpected token
fi' ./item_file.sh: line 9:
fi'If I write the same script using vi on the command line:
#!/bin/bash
echo "checking for the item file with vi"
item="item.txt"
if [ -r $item ]
then
echo "The item file exists and is readable"
else
echo "The item file does not exist or is not readable"
fi
It will run fine:
user@machine:/mnt/c/scripts$ ./item_file_2.sh
checking for the item file with vi
The item file does not exist or is not readable
At this point, I can open the second file with Sublime text and add code and it will run fine:
user@machine:/mnt/c/scripts$ ./item_file_2.sh
checking for the item file with vi
The item file does not exist or is not readable
checking for the item2 file with Sublime Text
The item2 file does not exist or is not readable
I can continue to add code to the file, including conditional statements, using Sublime Text and it will continue to run fine.
I have tried several things in Sublime Text to be able to code the file in this tool from the beginning with the same result. It will fail until I write the first conditional statement in vi on the command line. Once I do that, I can open the script in Sublime Text and it will be fine to use.
Windows Build: Microsoft Windows [Version 10.0.15063]
strace.txt
Thanks for help,
Pat
The text was updated successfully, but these errors were encountered: