<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>Tag: Bash - Ryan Daniels</title>
	<atom:link href="https://ryandaniels.ca/blog/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description></description>
	<lastBuildDate>Tue, 12 Dec 2023 03:57:12 +0000</lastBuildDate>
	<language>en-CA</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://ryandaniels.ca/wp-content/uploads/2019/07/img_5907-small-blur-square-100x100.jpg</url>
	<title>Tag: Bash - Ryan Daniels</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">22628916</site>	<item>
		<title>Run different Linux program based on current directory (using Bash shell)</title>
		<link>https://ryandaniels.ca/blog/run-different-linux-program-based-on-current-directory-using-bash-shell/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Sun, 26 Nov 2023 20:47:29 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Bash]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=2901</guid>

					<description><![CDATA[<p>This provides a way for using different versions of a program based on the current directory name. By adding this example code to the .bashrc file, users can run a unique terraform version based on the directory name.</p>
<p>The post <a href="https://ryandaniels.ca/blog/run-different-linux-program-based-on-current-directory-using-bash-shell/">Run different Linux program based on current directory (using Bash shell)</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Sometimes I want to use a specific version of a program, depending on the directory I&#8217;m currently in. With no obvious solution from <a href="https://stackoverflow.com/questions/tagged/linux+shell" target="_blank" rel="noreferrer noopener">Stack Overflow</a>, I&#8217;ll document my own.</p>



<p>I find this useful for my infrastructure as code configuration with terraform. Each directory is a different environment or site, and I can use different versions of terraform based on the name of the directory.</p>



<p>This is for bash shell on Linux. Tested on bash version 4.3 or newer. Might work on older version too.</p>



<p>Add this code to your .bashrc file:</p>



<pre class="wp-block-code"><code>function terraform () {
  case "${PWD##*/}" in
    *env-2023*) ~/terraform_1.6.2 "$@";;
    *) ~/terraform_0.11.15 "$@";; # default case
  esac
}</code></pre>



<p>Then log out and log back in.</p>



<h2 class="wp-block-heading">What is this doing?</h2>



<p>When you run the command &#8220;terraform&#8221;, your current directory is checked. If you are in a directory that has &#8220;env-2023&#8221; anywhere in it, then terraform_1.6.2 will run. Otherwise the (really) old version will run.</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>With this in your .bashrc file, you can have multiple directory patterns in the case syntax, each running a specific version of an application. I find this helpful when in the process of upgrading terraform config for all of my different environments for my infrastructure as code.</p>



<p>Here are some <a href="https://ryandaniels.ca/blog/tag/linux/">more Linux related posts</a>.</p>
<p>The post <a href="https://ryandaniels.ca/blog/run-different-linux-program-based-on-current-directory-using-bash-shell/">Run different Linux program based on current directory (using Bash shell)</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2901</post-id>	</item>
	</channel>
</rss>
