Case Statements in Linux are one of the efficient ways of selecting a condition in Linux.
Hi everyone, so I am very excited to share how to use case statement in Linux with Azure Devops. I have been working on C# for around 5 years and now working as a devops consultant in my current organization.
Most of my works are related to working on creating Azure Devops with Terraform and Ansible for infrastructure automation. One of the requirements that cam was to validate my variables against some of the values that has to be used while triggering the Azure Devops pipeline or we can say that by calling the azure devops api.
I am using a bash task with an inline script which we can use as given below:
case "$(os_type)" in "Red Hat") echo "Seleted value is $(os_type)." ;; "Windows Sever 2016") echo "Seleted value is $(os_type)." ;; "CentOS") echo "Seleted value is $(os_type)." ;; *) echo "Valid values for os_typeare "Red Hat", Windows Sever 2016 and CentOS." ;; esac
Here I am using a case statement to check the input value and compare it with the available values and echo the result.
Hope so that this will help you. Do let me know in the comments section if you need any help related to Azure Devops.
There have been times when I have copied some file from my computer with Windows on to a Linux server. Then I have found this issue very common. You can learn more about it here.
Today, while working I found a very strange error coming while trying to execute a Linux script. The error what I was getting said that script does not exits although, I was able to edit it using the vi editor.
After a long search found that the Linux was not able to read the file. as it was copied/ developed on a windows machine. So, there a very simple solution to this problem.
We have a package available i.e. dos2unix which can be installed on any flavor of Linux server and it can be used to convert the files into Linux readable files. Given below are the commands that we can use to install dos2unix
sudo yum install dos2unix -y
After we have installed dos2unix package we can execute a very simple command to convert the file so that unix system can easily interpret it or execute it.
Here file.sh is the file that needs to be converted to unix based file system.
Sign up for our newsletter to receive the latest news and event postings.