Flow control in Shell
While writing a Shell script, there may be a situation when you need to follow an external path 2 provided. So you need to create usage of conditional commands that allow your program to make accurate decisions and perform the right actions.
Unix Shell supports conditional commands that are used to perform various actions based on various conditions. Here we will explain two flow control commands:
If . else statement
The case . esac command
If . else command in Unix / Linux
This command is a useful flow control command, used to select an option from a given set of options.
Unix Shell supports the following if . else commands:
If . fi command
If . else . fi command
If . elif . else . fi command
Most if statements check relationships by using the relational operators mentioned in the previous chapter.
Case . esac command in Unix / Linux
You can use multiple if . elif commands to make a branch with multiple choices. However, this is not the best solution, especially when all branches depend on the value of a single variable.
Unix shell supports case . esac command which correctly resolves this situation, and it performs in a more efficient way than iterating using multiple if . elif commands.
There is only one sample of the case . esac command that is listed here:
The case . esac command
The case . esac command of Unix Shell is similar to the switch command . the case that we have in C or C ++ programs and PERL etc.
According to Tutorialspoint
Previous article: Operator Korn Shell
Next article: Loop in Unix / Linux
You should read it
May be interested
- What is Linux Shell? The most popular Linux Shellsare you satisfied using the bash shell in linux? or do you want to try an alternative? there are tsch, fish, kornshell and z shell for you to choose from. but which popular linux shell is best?
- Shell Sort in data structure and algorithmshell sort is a highly efficient sorting algorithm based on insertion sorting algorithm (insertion sort). this algorithm avoids the case of swapping positions of two distant elements in the selection algorithm (if the smaller element is in the right position quite far from the larger element on the left).
- How to download and play Mortal Shell PC for free forevermortal shell is an action role-playing game with gameplay similar to the famous dark souls. to survive in mortal shell you need to defeat enemies quickly, accurately and without mercy. if you are planning to play mortal shell pc for free, quickly get the mortal shell game for free on the epic store right away.
- Samsung Flow can be used on Windows 10 computersinterested users have also heard that samsung is updating the samsung flow application so everyone can use it on windows 10 pc.
- How to draw flow charts in Excelin this article, readers will learn how to set up a flowchart environment and create an excellent flow diagram in excel. some links for readers to download free microsoft excel flow charts will be placed at the end of the article.
- What is Classic Shell? How to use Classic Shell to customize Menu on Windows 10, 8, 7classic shell is a popular start menu custom application with stability and ease of use and operation. if you're fed up with the default start menu on windows, we can use and change the wind and customize the start menu to make your desktop fresher.
- Everything you can do with the new Windows 10 Bash Shellyou can install the linux environment and the bash shell on any version of windows 10. today's article will summarize what you can do in the new windows 10 bash shell.
- Steps to fix 'Shell Infrastructure Host Has Stopped Working' error in Windowsis your windows device showing 'shell infrastructure host has stopped working' error? in most cases, this problem occurs when running the application on a windows guest account.
- Guide to DD-WRT - Part 4: Definition of priorities with QoSyou can set up complex or simple qos rules on a $ 60 router like the linksys wrt54g and use the open-source dd-wrt software.
- Opera's Flow Usage to connect open tabs on computers and phonesopera touch provides flow feature, allowing you to synchronize open web, images, and videos between mobile devices and desktop computers. for flow to work, you must connect opera touch on your mobile device to opera desktop on your pc.