{"id":12151,"date":"2016-05-26T06:00:52","date_gmt":"2016-05-26T13:00:52","guid":{"rendered":"https:\/\/www.sapien.com\/blog\/?p=12151"},"modified":"2016-05-25T10:16:10","modified_gmt":"2016-05-25T17:16:10","slug":"using-bash-with-primalscript-2016","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2016\/05\/26\/using-bash-with-primalscript-2016\/","title":{"rendered":"Using Bash with PrimalScript 2016"},"content":{"rendered":"<p>I have been asked a few times now to use Bash with PrimalScript. It doesn\u2019t have all the setup for it out of the box because there are a few different implementations of Bash available for Windows. If you followed the latest news, Microsoft has announced at the BUILD 2016 keynote that Bash will become an integral part of Windows. (<a title=\"https:\/\/www.youtube.com\/watch?v=kJGqZHQzNRo\" href=\"https:\/\/www.youtube.com\/watch?v=kJGqZHQzNRo\">https:\/\/www.youtube.com\/watch?v=kJGqZHQzNRo<\/a>)<\/p>\n<p>Since we do not have the bits from Microsoft yet, I used the Cygwin Bash shell to demonstrate the necessary steps for PrimalScript 2016. You can download and install this version from here: <a title=\"https:\/\/cygwin.com\/install.html\" href=\"https:\/\/cygwin.com\/install.html\">https:\/\/cygwin.com\/install.html<\/a><\/p>\n<p>There are a few quirks that require manual intervention after the installation though.<\/p>\n<p>The installer will install the shell in your &#8220;C:\\cygwin&#8221; directory and when you launch bash.exe you get the bash-3.X$ prompt. However, although the pwd or cd commands work, if you try ls, it says:&#8221;ls: command not found&#8221;.<\/p>\n<p>Here is what you need to do to fix it:<\/p>\n<ol>\n<li>Right click on &#8220;My Computer&#8221; -&gt; Properties -&gt; Advanced -&gt; Environment Variables<\/li>\n<li>Add a new environment variable, called CYGWIN_HOME and set its value to C:\\cygwin<\/li>\n<li>Edit the PATH environment variable and add C:\\cygwin\\bin to it (usually separated by a &#8216;;&#8217;).<\/li>\n<li>Just click okay, exit any command prompts or bash shells (over cygwin) you may have open, and open it again &#8211; it&#8217;ll work!<\/li>\n<\/ol>\n<p>(Instructions taken from here: <a title=\"http:\/\/thehacklist.blogspot.com\/2009\/04\/cygwin-ls-command-not-found.html\" href=\"http:\/\/thehacklist.blogspot.com\/2009\/04\/cygwin-ls-command-not-found.html\">http:\/\/thehacklist.blogspot.com\/2009\/04\/cygwin-ls-command-not-found.html<\/a>)<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/05\/image.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/05\/image_thumb.png\" alt=\"image\" width=\"640\" height=\"347\" border=\"0\" \/><\/a><\/p>\n<p>Now that you have Bash running, there are two ways to add this to PrimalScript. Firstly to run bash shell scripts directly and secondly to have a Bash console embedded in PrimalScript.<\/p>\n<p>Adding a new shell to PrimalScript is very easy, since it already supports CMD and PowerShell. So just go to File \u2013 Options and select \u201cCommand Window\u201d<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/05\/SNAGHTMLbb8587.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"SNAGHTMLbb8587\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/05\/SNAGHTMLbb8587_thumb.png\" alt=\"SNAGHTMLbb8587\" width=\"640\" height=\"370\" border=\"0\" \/><\/a><\/p>\n<p>Please note that after you set this up you will need to restart PrimalScript.<\/p>\n<p>After the restart you need to make sure you have the shell windows made visible if you do not use them normally. On the View tab of the ribbon is a big \u201cShell\u201d button in the last group on the right.<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/05\/image-1.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/05\/image_thumb-1.png\" alt=\"image\" width=\"640\" height=\"100\" border=\"0\" \/><\/a><\/p>\n<p>When you see the console window docked on the bottom, you probably will see one of the default shells, CMD or PowerShell, depending on your OS version and setup. Use the combobox control on the top of the shell windows to switch to your Bash instance.<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/05\/image-2.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/05\/image_thumb-2.png\" alt=\"image\" width=\"640\" height=\"60\" border=\"0\" \/><\/a><\/p>\n<p>So there you are, a bash shell inside PrimalScript.<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/05\/image-3.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/05\/image_thumb-3.png\" alt=\"image\" width=\"640\" height=\"162\" border=\"0\" \/><\/a><\/p>\n<p>Ok, now we move on to running bash scripts.<\/p>\n<p>The file type template already exists in PrimalScript. When you select File \u2013 New, the \u201cBash\u201d type is in the first row.<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/05\/image-4.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/05\/image_thumb-4.png\" alt=\"image\" width=\"640\" height=\"143\" border=\"0\" \/><\/a><\/p>\n<p>Go to File \u2013 Options \u2013 Language and select \u201cBash\u201d from the list. Add the settings shown in the image below and press OK.<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/05\/SNAGHTMLbcb1e4.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"SNAGHTMLbcb1e4\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/05\/SNAGHTMLbcb1e4_thumb.png\" alt=\"SNAGHTMLbcb1e4\" width=\"640\" height=\"370\" border=\"0\" \/><\/a><\/p>\n<p>The Cygwin Bash implementation has, a mentioned before, a few quirks that Windows users may trip over. The line endings of bash scripts need to be linefeed only, as they are in Unix. Using Windows line endings will simple produce syntax errors, even on empty lines. You can change the line endings for a file in the properties as shown here:<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/05\/SNAGHTMLc02493.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"SNAGHTMLc02493\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/05\/SNAGHTMLc02493_thumb.png\" alt=\"SNAGHTMLc02493\" width=\"606\" height=\"269\" border=\"0\" \/><\/a><\/p>\n<p>(Right click in the file and select \u201cProperties\u2026\u201d to see this dialog)<\/p>\n<p>Last but not least, the Cygwin Bash shell does not understand Unicode. You must use plain old ASCII files. Using Unicode will result in an error message that binary files are not supported. So when you see that error, you know what to do.<\/p>\n<p>Right click on the encoding indicator on PrimalScript\u2019s status bar and change the encoding to \u201cASCII\u201d if it does not say that already.<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/05\/image-5.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/05\/image_thumb-5.png\" alt=\"image\" width=\"640\" height=\"201\" border=\"0\" \/><\/a><\/p>\n<p>Ok, now you are all set and you can use the \u201cRun\u201d button to launch your script. The output will show up in the output window, just like for any other script you run from PrimalScript.<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/05\/image-6.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2016\/05\/image_thumb-6.png\" alt=\"image\" width=\"408\" height=\"205\" border=\"0\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have been asked a few times now to use Bash with PrimalScript. It doesn\u2019t have all the setup for it out of the box because there are a few different implementations of Bash available for Windows. If you followed the latest news, Microsoft has announced at the BUILD 2016 keynote that Bash will become [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1115,2,410,514,21],"tags":[409,246,1117,37,236,1116],"class_list":["post-12151","post","type-post","status-publish","format-standard","hentry","category-bash","category-general","category-primalscript-software-news","category-quick-guide","category-software-news","tag-bash","tag-console","tag-cygwin","tag-primalscript","tag-shell","tag-unix"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/12151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=12151"}],"version-history":[{"count":4,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/12151\/revisions"}],"predecessor-version":[{"id":12155,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/12151\/revisions\/12155"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=12151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=12151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=12151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}