Skip to main content

Why should I know if condition in bash especially for Devops?

Hi All!

Today we're going to see and learn if / elseif condition in bash.

Everybody have a thought why if condition is main important to learn than other statements in bash. Let's see why

It is always good to have knowledge on powershell, python and especially bash as a Devops guy. Nowadays most of the organization prefers Infrastucture as Code (Iac) with DRY (Donot Repeat Yourself) mostly. i.e. single/same YAML code file should be applicable for their multiple environments.

Consider an example that an organization has Dev, QA and Production environments. They need same infra to be deployed on all the environments after the verification from Dev then QA then finally Production.

So here, Infrastucture is not going to change, only the environment gets changed (i.e. subscription, resourcegroup, resourcename ...etc,). so we should have a single YAML file based on condition.

But, why learning Bash "if condition" especially is a question here when python, powershell sripting tech available? because

"If condition" applied on YAML is as similar as bash script. so that if we know bash script, it will be easy to work with YAML with some logical aspects.

Note: I'm not saying that bash is best than other. Powershell, Bash and python all are suits based on need.

Please look into the below image, I have a single YAML with if-elseif for 3 environments in Azure Devops.

Comments

Popular posts from this blog

View powershell history and invoke Hi All! When you do administration activities, you may need to work around with multiple commands in powershell. It is bit difficul to remember all the commands we tried because some of them may be fetched from internet. Consider you tried more than 100 commands in current powershell session and may require to try the same large command. One of the way is you can press up arrow many times to see the previously tried command. we have another easy way is to see the history and invoke it by using its order number instead of whole command typing. Please look into the below example
Wow! Monitor web apps running in azure VM and VMSS via app insights Hi All! Application insights monitors the telemetry of web applications, function app, APIM and etc., Consider a scenario that your organization has some web applications hosted in IIS of an azure VM and they want to monitor performance of those applications. Azure VM was not the eligible candidate to map with Application insights then how can we monitor app(s) running inside azure VM? Now azure offers the feature of monitoring azure vm's web applications through application insights generally available. Please follow the below steps and have a look into the picture You need to have a connection string of an existing application insights. If have, copy it. Go to the VM which has web apps running in IIS Click "Extension+applications" and then click Add Find Application insights agent for .NET and click next Paste the copied connection string of app insights and click Review+Cre...
While loop with head and tail in linux Hi All! In today's post we're going to see/refresh about while loop with head and tail in bash. head - Read the first top 'n' lines. Example: head -n 5 reads first 5 lines from a file or input. tail - Read the last 'n' lines. Example: tail -n 5 reads last 5 lines from a file or input. Please look into the below image we have a txt file called file1.txt which has 3 lines of text and we read using head and tail as above.