<?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[Bash Tips and Tricks - Medium]]></title>
        <description><![CDATA[Bash tips and tricks that will save some time and lines. Writing a bash script it&#39;s easy, but are you using all Bash&#39;s power? Let&#39;s see ! - Medium]]></description>
        <link>https://medium.com/bash-tips-and-tricks?source=rss----cb288a6cfbbe---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Bash Tips and Tricks - Medium</title>
            <link>https://medium.com/bash-tips-and-tricks?source=rss----cb288a6cfbbe---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 10:19:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/bash-tips-and-tricks" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[An easy way to switch between runtime versions — NodeJS, Terraform, and +279]]></title>
            <link>https://medium.com/bash-tips-and-tricks/an-easy-way-to-switch-between-runtime-versions-nodejs-terraform-and-279-53fdfbcb4049?source=rss----cb288a6cfbbe---4</link>
            <guid isPermaLink="false">https://medium.com/p/53fdfbcb4049</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Matheus Lozano]]></dc:creator>
            <pubDate>Wed, 17 Feb 2021 21:03:19 GMT</pubDate>
            <atom:updated>2021-12-08T17:14:53.816Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<h3>An easy way to switch between runtime versions — NodeJS, Terraform, and +279</h3><h4>A CLI tool that can easily manage more than 281 runtimes, and it’s easy to add custom runtimes/plugins. It’s open-source!</h4><figure><img alt="How to keep tools updated. How to switch between versions on Linux" src="https://cdn-images-1.medium.com/max/1024/1*w-KgRbUGJsLWBNvHq-h3tg.png" /><figcaption>Screenshot from <a href="https://asdf-vm.com/#/"><strong>asdf website</strong></a></figcaption></figure><h3>Introduction</h3><p>There are many tools out there that promise to manage multiple runtimes and/or runtime versions, some are exclusive to a specific language, like the <a href="https://github.com/pyenv/pyenv">pyenv</a> and others can manage multiple runtimes, but it’s not easy to switch between the versions of the same runtime, like the <a href="https://brew.sh/">Homebrew</a> (You can unlink/link, but in my opinion, it’s too unstable).</p><p>Here comes the asdf, yes, this is the name. Simple name, simple to use! asdf is an open-source tool under the MIT License. Currently, it supports 281 runtimes, also known as plugins. You can use it to switch between runtimes versions or just to keep things updated.</p><p>asdf is very easy to use, it’s very intuitive, and it’s easy to customize in case you want to add/change plugins.</p><h3>Pre-requirements</h3><p>Thanks to most of the shell builtin, asdf don’t have a long list of requirements.</p><p>These are the basic requirement to use asdf. Other requirements may be included. Some plugins need to be compiled (e.g.: via Makefile), others use wget or curl to download the binary.</p><ul><li>Bash / Zsh / Fish</li><li>Git</li></ul><h3>How it works</h3><p>asdf is a, let’s say, Bash toolbox. Most of the commands used are shell builtin and this is one of the greatest things about this tool, and it’s why is portable to other Operational Systems, you can even run on Windows (it needs a bit of customization, but it’s possible).</p><h4>Plugins</h4><p>Each plugin is a runtime that points to a git repository and contains all the basic functions, like list the versions available and what needs to be done to install the plugin. The plugin’s git repository is also a collection of Bash scripts.</p><h4>Scopes</h4><p>There are three scopes that you can install a plugin version.</p><ul><li><strong>Global</strong> =&gt; It sets the “default” version, that means it can be used from anywhere. The file with all global versions can be found on ~/.tool-versions.</li><li><strong>Local</strong> =&gt; It sets the version to be used only in the current folder. This has a high priority over the Global . The file with all local versions can be found on ${PWD}/.tool-versions.</li><li><strong>Shell</strong> =&gt; It sets the version to be used only in the current shell session. This has a high priority over the Global and Local. There is no file, it sets an environment variable ASDF_&lt;PLUGIN&gt;_VERSION.<br><em>If you don’t know what is an environment variable on Bash, check my post about it: </em><a href="https://medium.com/unboxing-the-cloud/bash-variables-things-that-you-probably-dont-know-about-it-8a5470887331"><em>https://medium.com/unboxing-the-cloud/bash-variables-things-that-you-probably-dont-know-about-it-8a5470887331</em></a></li></ul><h3>How to use</h3><figure><img alt="How to switch between version on Linux" src="https://cdn-images-1.medium.com/max/1024/1*6rp-x1K8On3jtZCLo0-XmQ.jpeg" /><figcaption>Image by <a href="https://unsplash.com/@kellysikkema"><strong>Kellysikkema</strong></a> on <a href="https://unsplash.com/photos/f4ELzp_WuCk"><strong>Unsplash</strong></a></figcaption></figure><p>There are quite some quite options that can be used, these are just a few of them.</p><h4>Updating asdf</h4><p>It’s very simple to keep asdf update, all you need to do is to run one of the commands below.</p><pre>## Get from the latest tag<br>asdf update<br>## or to get from the master branch<br>asdf update --head</pre><h4>Straight away</h4><p>This is an example of how you can use asdf , from scratch (excluding the installation of asdf itself).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/016fa911b9bdf975204fe7b1462946d2/href">https://medium.com/media/016fa911b9bdf975204fe7b1462946d2/href</a></iframe><h4>Switching between versions</h4><p>Here is an example of how you can switch between versions of the same runtime.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2790ff7c60f45df7742e80d0ed6393d/href">https://medium.com/media/c2790ff7c60f45df7742e80d0ed6393d/href</a></iframe><h3>My considerations</h3><p>I start using asdf somewhere in 2017 for personal things and in production environments (CI/CD pipelines) since the end of 2019. It’s very stable, helps a lot when you need to have multiple versions of a tool, or just want to keep something updated. I start loving this tool when I start using it on CI/CD pipelines. Sometimes I had to use a different version or a specific version for a specific project. At that time, I was going to update the terraform code, it was just too much code to update all at once. With asdf, all I had to do is to create the file .tool-versions per project.</p><p>Also, because asdf uses the official packages and most of the plugins are using shell builtin commands, it makes it easier/stable to work with.</p><h3>Read more</h3><ul><li><a href="https://asdf-vm.com/#/">asdf - An extendable version manager</a></li><li><a href="https://github.com/asdf-vm/asdf">GitHub - asdf-vm/asdf: Extendable version manager with support for Ruby, Node.js, Elixir, Erlang &amp; more</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53fdfbcb4049" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bash-tips-and-tricks/an-easy-way-to-switch-between-runtime-versions-nodejs-terraform-and-279-53fdfbcb4049">An easy way to switch between runtime versions — NodeJS, Terraform, and +279</a> was originally published in <a href="https://medium.com/bash-tips-and-tricks">Bash Tips and Tricks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The first Newsletter —]]></title>
            <link>https://medium.com/bash-tips-and-tricks/the-first-newsletter-111678ced091?source=rss----cb288a6cfbbe---4</link>
            <guid isPermaLink="false">https://medium.com/p/111678ced091</guid>
            <category><![CDATA[newsletter]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Matheus Lozano]]></dc:creator>
            <pubDate>Mon, 01 Feb 2021 19:06:56 GMT</pubDate>
            <atom:updated>2021-02-01T19:14:46.991Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<h3>The first Newsletter — A catch-up of January/2021</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*lu1n5qvqY41qCFbTG6_4aA.png" /></figure><h3>About the blog</h3><p>It’s divided into a few categories. The main categories right now are the Tips &amp; Tricks (<a href="https://medium.com/aws-tips-and-tricks">for AWS</a> and <a href="https://medium.com/bash-tips-and-tricks">for Bash</a>) and the <a href="https://medium.com/news-updates-and-reminders-cloud-devops-sre-chaos">News, Updates and Reminders</a>.</p><p>I’ll be posting twice a week:</p><p><strong>1x Tips &amp; Tricks</strong> = Every Wednesday at 19:00 UTC</p><p><strong>1x News, Updates and Reminders</strong> = Every Sunday at 19:00 UTC</p><blockquote>The replicas are posted on <a href="https://lozanomatheus.com/">https://lozanomatheus.com</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*dhz0DNazQkl7WEsgnFNi7g.png" /></figure><h3><a href="https://medium.com/bash-tips-and-tricks">Bash Tips &amp; Tricks</a></h3><p><a href="https://medium.com/bash-tips-and-tricks/newsletters/bash-tips-and-tricks"><strong>Join the Newsletters</strong></a></p><p><a href="https://medium.com/bash-tips-and-tricks/how-to-trigger-an-action-at-the-end-of-the-shell-bash-script-52b0ba9c157e"><strong>How to trigger an action at the end of the Shell/Bash script</strong></a><br>Using Bash/Shell trap, a built-in command to define any action to be executed before exiting the Bash or Shell script. You can define multiple actions and per signal</p><p><a href="https://medium.com/bash-tips-and-tricks/getting-the-linux-ip-address-without-any-package-ifconfig-ip-address-etc-7b1363077964"><strong>Getting the Linux IP address without any package (ifconfig, ip address, etc)</strong></a><br>How to get Linux IP address, netmask and gateway without ifconfig or ip commands</p><p><a href="https://medium.com/bash-tips-and-tricks/part01-tcp-udp-request-with-a-native-bash-feature-and-without-curl-wget-9dcef59c30aa?sk=a48b13d9d2406f25e1ac9df4115ff3de"><strong>Part01 — TCP/UDP request with a native Bash feature and without curl/wget/*</strong></a><br>Sending HTTP / TCP / UDP requests via Bash without using any other tool</p><h3>The last post of</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tFl-8wQUENETYLjX5mYWuA.png" /></figure><h4><a href="https://medium.com/aws-tips-and-tricks">AWS Tips and Tricks</a></h4><p><a href="https://medium.com/aws-tips-and-tricks/newsletters/aws-tips-and-tricks"><strong>Join the Newsletter</strong></a></p><p><a href="https://medium.com/aws-tips-and-tricks/how-to-use-aws-iam-role-on-aws-eks-pods-5e9e7bb1de9a?sk=4703252173e37c992d871277967d59c7"><strong>How to use AWS IAM role on AWS EKS PODs</strong></a><br>A native-AWS way to attach an IAM role into the Kubernetes POD, without third party software</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/70/1*dvUBBMK6vk0DG-NF0prfBg.jpeg" /></figure><h4><a href="https://medium.com/news-updates-and-reminders-cloud-devops-sre-chaos">News, Updates and Reminders</a></h4><p><a href="https://medium.com/news-updates-and-reminders-cloud-devops-sre-chaos/newsletters/news-updates-and-reminders"><strong>Join the Newsletter</strong></a></p><p><a href="https://medium.com/news-updates-and-reminders-cloud-devops-sre-chaos/week04-news-updates-reminders-aws-hashicorp-istio-linux-7e4883cc7243?sk=08d299f343869ae9951fc9f42f852299"><strong>Week04 — News, Updates &amp; Reminders — AWS | HashiCorp | Istio | Linux</strong></a><br>News from AWS, HashiCorp, Istio and Linux. Reminder for the Linux patch update and the end of support of Istio, AWS EKS and AWS RDS.</p><h3>Feedbacks, suggestions, comments</h3><p>Please, feel free to e-mail me with any feedback, suggestion, comment, *. You can do it by replying this e-mail or sending an e-mail to <a href="/service/mailto:tcp-f@lozanomatheus.com">tcp-f@lozanomatheus.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=111678ced091" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bash-tips-and-tricks/the-first-newsletter-111678ced091">The first Newsletter —</a> was originally published in <a href="https://medium.com/bash-tips-and-tricks">Bash Tips and Tricks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to trigger an action at the end of the Shell/Bash script]]></title>
            <link>https://medium.com/bash-tips-and-tricks/how-to-trigger-an-action-at-the-end-of-the-shell-bash-script-52b0ba9c157e?source=rss----cb288a6cfbbe---4</link>
            <guid isPermaLink="false">https://medium.com/p/52b0ba9c157e</guid>
            <category><![CDATA[bash-script]]></category>
            <category><![CDATA[shell]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[trap]]></category>
            <dc:creator><![CDATA[Matheus Lozano]]></dc:creator>
            <pubDate>Thu, 28 Jan 2021 22:05:23 GMT</pubDate>
            <atom:updated>2021-12-08T17:16:11.322Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<h4>Using Bash/Shell trap, a built-in command to define any action to be executed before exiting the Bash or Shell script. You can define multiple actions and per signal.</h4><figure><img alt="List of signals that can be used on Bash / Shell trap" src="https://cdn-images-1.medium.com/max/1024/1*NhtW27q-oNBLIRw-17G2ZA.jpeg" /><figcaption>List of trap signals</figcaption></figure><blockquote>trap — ‘’ SIGTSTP<br>trap — ‘’ SIGTTIN<br>trap — ‘’ SIGTTOU</blockquote><h3>How it works</h3><p>The Bash/Shell trap is a built-in command that can be used to trigger an action at the end of the script according to the signal. For example, you can use the ERR to run a function in case something goes wrong. Use the EXIT signal to run something every time that exists the script.</p><p><em>Note: Defining another action within the same signal will override the trap.</em></p><blockquote>The Shell Trap built-in command and it’s available on most of the Linux and Unix distributions.</blockquote><h4>Signals available</h4><p>Currently, there are 65 signals (62 listed + 3) and not all of them are supported. You can list the signals available by running trap -l . The other three are DEBUG, EXIT and ERR.</p><figure><img alt="List of signals that can be used on Bash / Shell trap" src="https://cdn-images-1.medium.com/max/1024/1*NhtW27q-oNBLIRw-17G2ZA.jpeg" /><figcaption>List of trap signals</figcaption></figure><h3>Versions</h3><p>These are the versions that I’m using.</p><pre>CentOS Linux release 7.9.2009<br>Linux 4a48b06b2344 4.19.121-linuxkit<br>Bash =&gt; 4.2.46(2)-release<br>cURL =&gt; 7.29.0</pre><h3>Examples</h3><h4>A code example</h4><p>This example I will show what happens if the curl has an invalid URL.</p><p><em>Note: The first function </em><em>log is for logging purpose only and I’ll be covering this in a future post. For now, let’s focus on the function </em><em>fatal_log and the </em>trap fatal_log ERR<em>.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e49952d0dccea44ab642e4c185fc011/href">https://medium.com/media/2e49952d0dccea44ab642e4c185fc011/href</a></iframe><h4>Exampling the code</h4><p>At the beginning of the fatal_log function, I defined three local variables. The intention was to preserve the return code from the failed command and use it to exit from the script.</p><ol><li>return_codes =&gt; Has the return code of the last command, including the pipes. For example, if you run ls -l | grep -i aaa and there is no aaa file, the last command with the error was the grep with return code 1</li><li>array_length =&gt; This is to check the length of the array return_codes</li><li>return_code =&gt; It’s the last return code of the return_codes</li></ol><p>After defining the local variables, I create a function log to print a FATAL error in the terminal and send a notification via Slack.</p><h4>A live example</h4><p>In the video below, you can confirm the order mentioned above.</p><ol><li>Run the script ./trap.sh</li><li>Get the curl: (6) error</li><li>Print the FATAL message</li><li>Get the ok from Slack</li><li>And finally confirming the exit code of the script</li></ol><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FKZGQG7QAwG0%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DKZGQG7QAwG0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FKZGQG7QAwG0%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/56106c527b20c13408ca782c8ab5e71a/href">https://medium.com/media/56106c527b20c13408ca782c8ab5e71a/href</a></iframe><h3>Read more</h3><ul><li><a href="https://linuxcommand.org/lc3_man_pages/traph.html">trap man page</a></li><li><a href="https://www.linuxjournal.com/content/bash-trap-command">The Bash Trap Command</a></li><li><a href="https://linuxhint.com/bash_trap_command/">Bash trap command</a></li><li><a href="https://www.computerhope.com/unix/bash/declare.htm">Bash declare builtin command help and examples</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52b0ba9c157e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bash-tips-and-tricks/how-to-trigger-an-action-at-the-end-of-the-shell-bash-script-52b0ba9c157e">How to trigger an action at the end of the Shell/Bash script</a> was originally published in <a href="https://medium.com/bash-tips-and-tricks">Bash Tips and Tricks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting the Linux IP address without any package (ifconfig, ip address, etc)]]></title>
            <link>https://medium.com/bash-tips-and-tricks/getting-the-linux-ip-address-without-any-package-ifconfig-ip-address-etc-7b1363077964?source=rss----cb288a6cfbbe---4</link>
            <guid isPermaLink="false">https://medium.com/p/7b1363077964</guid>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[kernel]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[shell]]></category>
            <dc:creator><![CDATA[Matheus Lozano]]></dc:creator>
            <pubDate>Mon, 30 Nov 2020 22:01:54 GMT</pubDate>
            <atom:updated>2021-12-08T17:17:26.237Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<h4>How to get Linux IP address, netmask and gateway without ifconfig or ip commands</h4><figure><img alt="How to get Linux IP without ipconfig or ip address" src="https://cdn-images-1.medium.com/max/600/1*K9xtLBAL3oqQzP6qyR_1Sw.png" /></figure><blockquote>bash: ip: command not found<br>bash: ifconfig: command not found</blockquote><h3>Explaining how it works</h3><p>How many times you tried to debug/troubleshoot a Linux with an unprivileged user and you didn’t have net tools or iproute installed? Well, the good news is: You can do it with Bash (ok ok, this not a bash feature :’), without having to install any package.</p><p>Many information displayed by those tools are available by the Kernel and most of them doesn’t require a privileged user. Cool, right?</p><p>In order to understand how this is possible, we’re going to explore~very shortly~ the IPv4 Routing Subsystem, in specifically the Forwarding Information Base trie (Aka FIB trie). The FIB trie is the main data structure used by the IPv4, it defines the routing trie and can be used by us to collect our IP addresses, gateway IP, netmask, etc.</p><figure><img alt="fibtrie example — Showing the IP address, netmaks and gateway" src="https://cdn-images-1.medium.com/max/423/1*IZNsUAmxBRtfAF3b2_Ou4Q.png" /><figcaption>Routing trie till 192.0.2.48/32 — Credits <a href="http://vincent.bernat.ch/">vincent.bernat.ch</a></figcaption></figure><p>As I said, very sort :D. Now let’s get our IPs!</p><p>The file that contains the routing trie is the <strong>/proc/net/fib_trie </strong>and you can use the commands below to filter and get only the desired IPs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/768ab65cfc0f2253b815fb2831ace02b/href">https://medium.com/media/768ab65cfc0f2253b815fb2831ace02b/href</a></iframe><blockquote>It’s important to notice that the first command is removing the <strong>*.0</strong> and <strong>*.255</strong>, if you have a network bigger than /24 (netmask 255.255.255.0) you may not get your desired IPs.</blockquote><p><strong>Read more<br></strong><a href="https://vincent.bernat.ch/en/blog/2017-ipv4-route-lookup-linux">IPv4 route lookup on Linux by Vincent Bernat</a><br><a href="https://apprize.best/linux/kernel/6.html">The IPv4 Routing Subsystem</a><br><a href="https://www.kernel.org/doc/html/latest/networking/fib_trie.html">FIB trie</a><br><a href="https://www.researchgate.net/publication/267149681_Competitive_FIB_Aggregation_for_Independent_Prefixes_Online_Ski_Rental_on_the_Trie">Competitive FIB Aggregation for Independent</a><br><a href="https://www.computer.org/csdl/journal/nt/2018/04/08424420/13rRUx0genI">Constant IP Lookup With FIB Explosion</a><br><a href="https://en.wikipedia.org/wiki/Trie">Trie - Wikipedia</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b1363077964" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bash-tips-and-tricks/getting-the-linux-ip-address-without-any-package-ifconfig-ip-address-etc-7b1363077964">Getting the Linux IP address without any package (ifconfig, ip address, etc)</a> was originally published in <a href="https://medium.com/bash-tips-and-tricks">Bash Tips and Tricks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part01 — TCP/UDP request with a native Bash feature and without curl/wget/*]]></title>
            <link>https://medium.com/bash-tips-and-tricks/part01-tcp-udp-request-with-a-native-bash-feature-and-without-curl-wget-9dcef59c30aa?source=rss----cb288a6cfbbe---4</link>
            <guid isPermaLink="false">https://medium.com/p/9dcef59c30aa</guid>
            <category><![CDATA[bash-script]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[linux-tutorial]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[terminal]]></category>
            <dc:creator><![CDATA[Matheus Lozano]]></dc:creator>
            <pubDate>Fri, 05 Jul 2019 23:09:48 GMT</pubDate>
            <atom:updated>2021-12-08T17:17:37.851Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<h3>Part01 — TCP/UDP request with a native Bash feature and without curl/wget/*</h3><h4>Sending HTTP / TCP / UDP requests via Bash without using any other tool</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*K4frRTMDBMTDEMOiB4CaUw.gif" /></figure><blockquote>bash: wget: command not found<br>bash: curl: command not found</blockquote><h3>Explaining how it works</h3><p>How many times you tried to test an application or service and you couldn&#39;t because you don&#39;t have curl/wget/telnet/* installed and the user doesn&#39;t have permission to install? Well, the good news is: You can do it with Bash, by native.</p><p>One of the optional features (also a default one) for Bash is the <strong>--{enable,disable}-net-redirections</strong>. With this feature, you can send TCP or UDP requests in many ways.</p><blockquote>If host is a valid hostname or Internet address, and port is an integer port number or service name, Bash attempts to open the corresponding TCP/UDP socket.</blockquote><p>It&#39;s possible to do it because of the pseudo devices under the <strong>/dev/</strong>. They&#39;re <strong>/dev/tcp</strong> and <strong>/dev/udp</strong>.</p><p>The structure for this feature/pseudo devices are:<br><strong>/dev/PROTOCOL/HOST/PORT</strong></p><p>For example:<br><strong>/dev/tcp/google.com/443<br>/dev/udp/192.168.0.10/123</strong></p><p>So, base on that, you can send many times of requests using this Bash feature, from HTTP to NTP. Also, you can get the result back, if you want.</p><blockquote><em>By default, the feature </em><strong><em>net-redirections</em></strong><em> is enabled on Bash.</em></blockquote><h3><strong>A simple example</strong></h3><p>To send this request, I create the examples below. These examples are sending a true value to <em>localhost</em> and also <em>google.com.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49852b67501ab3386a23f38646677805/href">https://medium.com/media/49852b67501ab3386a23f38646677805/href</a></iframe><h3><strong>A possible error</strong></h3><p><em>No such file or directory</em> =&gt; If you&#39;re getting this error during the execution, it&#39;s because your Bash don&#39;t have the feature <strong>net-redirections</strong> enabled.</p><p>For example:</p><blockquote><em>:&gt; /dev/tcp/google.com/443<br>bash: /dev/tcp/google.com/443: No such file or directory</em></blockquote><blockquote>: Is the short version of true. Could also be:<br>true &gt; <em>/dev/tcp/google.com/443</em></blockquote><p>To fix this error, you can use this script. It will install Bash with <strong>net-redirections</strong>. This script can be used on Ubuntu, CentOS and Alpine.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/959e4a45492d50f028019a150115f659/href">https://medium.com/media/959e4a45492d50f028019a150115f659/href</a></iframe><h4>Read more</h4><p><a href="https://www.gnu.org/software/bash/manual/bash.html#Optional-Features">Bash - Optional Features</a><br><a href="https://www.gnu.org/software/bash/manual/bash.html#Redirections">Bash - Redirections</a><br><a href="https://learning.oreilly.com/library/view/bash-cookbook/0596526784/ch15s09.html">Bash - Cookbook</a><br><a href="https://ceh51.blogspot.com/2016/07/how-to-open-tcpudp-sockets-bash-shell.html">Bash - How to open TCP/UDP sockets</a><br><a href="https://www.linuxjournal.com/content/tech-tip-tcpip-access-using-bash">Tech Tip: TCP/IP Access Using bash</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9dcef59c30aa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bash-tips-and-tricks/part01-tcp-udp-request-with-a-native-bash-feature-and-without-curl-wget-9dcef59c30aa">Part01 — TCP/UDP request with a native Bash feature and without curl/wget/*</a> was originally published in <a href="https://medium.com/bash-tips-and-tricks">Bash Tips and Tricks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>