<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Harshit Sinha on Medium]]></title>
        <description><![CDATA[Stories by Harshit Sinha on Medium]]></description>
        <link>https://medium.com/@harshitsinha1102?source=rss-3cac1d11810------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*u_3RFsVoF9KB7ZOsPw50MA.jpeg</url>
            <title>Stories by Harshit Sinha on Medium</title>
            <link>https://medium.com/@harshitsinha1102?source=rss-3cac1d11810------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 05:48:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@harshitsinha1102/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Cross Platform Portable Shell Scripts Using Node]]></title>
            <link>https://medium.com/@harshitsinha1102/cross-platform-portable-shell-scripts-using-node-69c63e7b578?source=rss-3cac1d11810------2</link>
            <guid isPermaLink="false">https://medium.com/p/69c63e7b578</guid>
            <category><![CDATA[shell]]></category>
            <category><![CDATA[cross-platform]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[shellscripting]]></category>
            <category><![CDATA[command-line]]></category>
            <dc:creator><![CDATA[Harshit Sinha]]></dc:creator>
            <pubDate>Mon, 24 Dec 2018 16:01:42 GMT</pubDate>
            <atom:updated>2018-12-26T07:25:20.470Z</atom:updated>
            <content:encoded><![CDATA[<h3>Cross Platform Portable Shell Scripts Using Node.js</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*UApYhNlsE3SVyIad__FHnw.jpeg" /></figure><p>Tired of writing and maintaining multiple Command Line scripts (shell / batch) for various platforms (Ubuntu/Windows/Mac) ?</p><p>Here’s a one stop solution implemented in Node.js for easing your life - <a href="https://documentup.com/shelljs/shelljs">Shelljs</a>.</p><p>You will not only ensure that a single copy of script runs on all platform but also don’t have to bother about gaining expertise in multiple scripting languages.</p><h3>Prerequisites -</h3><h3>Knowledge -</h3><ul><li>Basic JavaScript knowledge.</li><li>Shell Scripting knowledge.</li></ul><h3>Tools -</h3><ul><li><a href="https://nodejs.org/en/download/">Node.js</a></li><li>Npm (Comes bundled along with Node.js)</li></ul><h3>Setup -</h3><ul><li>Make a directory for the scripts project</li><li>Navigate to the scripts project directory</li><li>Initialize npm in the given project using npm init. Accept all the default values by pressing enter at each step</li><li>Install shelljs as an npm dependency</li></ul><pre>mkdir shell-scripts<br>cd shell-scripts/<br>npm install --save shelljs<br>npm init</pre><ul><li>A package.json file will be created in the directory</li></ul><pre>{</pre><pre>     &quot;name&quot;: &quot;shell-scripts&quot;,</pre><pre>     &quot;version&quot;: &quot;1.0.0&quot;,</pre><pre>     &quot;description&quot;: &quot;&quot;,</pre><pre>     &quot;main&quot;: &quot;index.js&quot;,</pre><pre>     &quot;scripts&quot;: {</pre><pre>         &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;</pre><pre>     },</pre><pre>     &quot;author&quot;: &quot;&quot;,</pre><pre>     &quot;license&quot;: &quot;ISC&quot;,</pre><pre>     &quot;dependencies&quot;: {</pre><pre>         &quot;shelljs&quot;: &quot;^0.8.3&quot;</pre><pre>     }</pre><pre>}</pre><ul><li>Directory Structure will look like -</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/189/0*JgRzSE7wXKTRSEo_" /></figure><h3>Scripting -</h3><ul><li><strong>Basic Commands (pwd, cd, echo, mkdir)</strong> - Here’s a program showing commonly used commands</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/53b895dc0ab42c05d97c9b16e54b6b93/href">https://medium.com/media/53b895dc0ab42c05d97c9b16e54b6b93/href</a></iframe><p>Output -</p><pre><strong>shell-scripts harshitsinha$</strong> node test_script.js</pre><pre>Current Directory /Users/harshitsinha/Desktop/random_tests/shell-scripts</pre><pre>Navigating to temp folder inside current directory</pre><pre>New Current Directory /Users/harshitsinha/Desktop/random_tests/shell-scripts/temp</pre><pre>Navigating back to project root</pre><pre>Current Directory /Users/harshitsinha/Desktop/random_tests/shell-scripts</pre><pre>Files/Folders in Directory /Users/harshitsinha/Desktop/random_tests/shell-scripts</pre><pre>- node_modules</pre><pre>- package.json</pre><pre>- temp</pre><pre>- test_script.js</pre><pre>Making a directory name tempDir</pre><ul><li><strong>More commands (grep, cp, cat, sed)</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/34aee7fc54c5774752607c3ea45378ad/href">https://medium.com/media/34aee7fc54c5774752607c3ea45378ad/href</a></iframe><p>Output -</p><pre><strong>shell-scripts$</strong> node test_script2.js</pre><pre>Grepped lines with word total<br>Line -  total is used for testing purposes<br>Line -  We will again drop a total here<br>Line -</pre><pre>Copying file ./temp/file1.txt to ./temp/file1-copy.txt</pre><pre>Replacing in place all occurences of &#39;if&#39; with &#39;but&#39; in file</pre><pre>Displaying text of file using cat<br>Hi this is a sample text file<br>total is used for testing purposes<br>We will again drop a total here<br>if we can keep on continuing this difficult process we will have a good test example.<br>Grep lines with word &#39;total&#39; from ./temp/file1.txt, then replace &#39;total&#39; with &#39;totalReplaced&#39; then output final file to ./temp/out.txt</pre><p>For more examples <a href="https://github.com/shelljs/shelljs">refer</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69c63e7b578" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>