Home > bash > Are there any implications of closing every if-block with fi in a nested if-construct?

Are there any implications of closing every if-block with fi in a nested if-construct?

February 12Hits:0
Advertisement

As closing "fi"s for nested if-blocks are not necessary except for when delimiting else-blocks (ref: http://stackoverflow.com/a/15328027/1942997), I was wondering if there were any implications when doing this or if it is just a matter of style.

Example Code 1:

if [ condition ]; then     echo "Not nested, condition 1 true"     if [ other_condition ]; then         echo "Nested, condition 2 true"     else         echo "Nested, condition 2 false"     fi fi 

Example Code 2 (notice the missing last fi):

if [ condition ]; then     echo "Not nested, condition 1 true"     if [ other_condition ]; then         echo "Nested, condition 2 true"     else         echo "Nested, condition 2 false" fi 

Being used to closing every if block with curly brackets from other languages, it only seems reasonable to me to keep this behavior in bash scripting. The only impact I could think of was the marginally increased file size of the script in favor of better readability.

Answers

You tagged this as bash; I get "syntax error: unexpected end of file" if I don't close the inner if.

The referenced SO Q says:

In bash there isn't such a thing as every if has to be delimited by a companion fi marking the end of the if block.

which could be understood two ways:

The wrong way:

In bash there isn't such a thing as: "every if has to be delimited by a companion fi marking the end of the if block."

The right way:

In bash there isn't such a thing [as dangling else ambiguity], as every if has to be delimited by a companion fi marking the end of the if block.

Related Articles

  • Are there any implications of closing every if-block with fi in a nested if-construct?February 12

    As closing "fi"s for nested if-blocks are not necessary except for when delimiting else-blocks (ref: http://stackoverflow.com/a/15328027/1942997), I was wondering if there were any implications when doing this or if it is just a matter of style.

  • debian: count connections/traffic to closed portsAugust 27

    I got a new VPS on the same machine on which I already have a VPS. But up-/download is much slower on the new VPS. Is there a possibility to check if there are clients trying to connect to a closed port and block the bandwith with these requests? For

  • How can I keep reading from a pipe even after the pipe is closed?June 10

    I've got a ksh script that calls: while read LINE do... The input has been redirected (not shown) so that it reads input from a pipe. The problem is that when the writer to the pipe closes, read returns false and exits the loop. I want it to keep rea

  • Resultset and CallableStatement is not closing after processingJanuary 19

    I am trying to close ResultSet and CallableStatement after processing but only Connection is closing and other two don't. final String procedureCall = "{call GET_PAWS_PERSON_DETAILS(?, ?)}"; try { //Get Connection instance from dataSource connec

  • batch for loop with bracket in the commandMay 28

    I have a batch file with the following code: for /f "tokens=*" %%a in ('dir /b /a-d') do ( echo Processing %%a >>%LOG% dtsrun /S(local) /NNotesLoad /A"FilePath:8="%NOTESDIR%\%%a" /AClientID=%1 >>%LOG% echo Deleting %%a

  • SSH Tunnel using PuTTY no longer works after server changeAugust 12

    EDIT (for clarification) Windows Client Remote Linux Server |----------------------------------| |---------------------| ____________ ____________ ____________ | | | | | | | Firefox | -------> | PuTTY | -------> | sshd | ---> (The Internet) |____

  • What mistakes in managing software products must be avoided to keep people from hating the vendor?November 23

    A previous question about why people hate Microsoft was closed. This is an attempt at a somewhat more constructive question along the same general line. This one is both broader and narrower though. It's more general by being about software vendors i

  • MDADM Array Being Limited to 2.0TBDecember 13

    I have an MDADM array with four 1TB disks in a RAID5 configuration. Here's the relevant part of mdadm --detail /dev/md1: Version : 00.90 Raid Level : raid5 Array Size : 2929537920 (2793.83 GiB 2999.85 GB) Used Dev Size : 976512640 (931.28 GiB 999.95

  • Can I use a multi-line function or control flow segment into the PowerShellFar editor consoleFebruary 24

    If I am running farmanager with FarNet and PowerShellFar I can bring up a console of sorts by selecting F11 | .NET PowerShell | Editor Console. This console is based on the far editor. I can paste snippets of powershell scripts into this console and

  • Virtualhost cannot occur withing VirtualHost section

    Virtualhost cannot occur withing VirtualHost sectionAugust 10

    I can't set the vhost config for a subdomain. When I put something in it like <VirtualHost *:80> ServerName redmine.website.de ServerAdmin [email protected] DocumentRoot /usr/share/redmine/public </VirtualHost> and reconfigure vhost I get th

  • How can I make tags visible using this tumblr theme?September 23

    I've made several attempts to add tags to my tumblr posts, but each time I try to edit the theme I end up with a list of tags across the top of my blog instead of included in each seperate post. Can anyone tell me how to edit the theme below to add t

  • Why JSLint run : "Expected exactly one space between-" November 15

    Why JSLint report in code: function cos(a) { var b = 0; if (a) { b = 1; } else { b = 2; } return b; } error: Problem at line 6 character 5: Expected exactly one space between '}' and 'else'. This error can be turn off by disabling Tolerate messy whit

  • Why don't we use SetDelayed when we use placeholder to declare a function? January 26

    Every time I define a new function, I wonder which construct I should use: true functions obtained by using Function, or rule-based syntax. For example, these are two ways of defining a square function: square = Function[x, x^2] (* Alternatively: squ

  • Using anonymous functions instead of module or block. Bad idea? January 26

    I've seen people compare Block with Module and With as scoping constructs, and try to figure out when to choose which. Also, I've seen posts about Function versus # versus downvalue functions. However, I already understood the differences between tho

  • nginx proxy configuration error (config syntax)February 8

    Hihi, below is the config + error it's throwing, can't for the life of me figure out what's wrong. Tried all sorts to get it working to no avail :( server { listen 127.0.0.1:100; access_log /var/log/nginx/main.proxied.log; location ^~/(error_pages|ja

  • DRBD Not syncing between my nodesMarch 21

    Some version info: Operating system is Ubuntu 11.10, on EC2, kernel is 3.0.0-16-virtual and the application info is: Version: 8.3.11 (api:88) GIT-hash: 0de839cee13a4160eed6037c4bddd066645e23c5 build by [email protected], 2011-07-05 19:51:07 Getting som

  • Are there any other causes of this error that are NOT related to initial setup?April 3

    I'm trying to diagnose an issue at a customer site. They are receiving the following error: A network-related or instance-specific error occurred while establishing a connection to SQL Server I've seen this a few times, but only during the initial se

  • What are the advantages of using nullptr?December 11

    This piece of code conceptually does the same thing for the three pointers (safe pointer initialization): int* p1 = nullptr; int* p2 = NULL; int* p3 = 0; And so, what are the advantages of assigning pointers nullptr over assigning them the values NUL

  • Do not show a custom post if it belongs to a certain custom taxonomyJanuary 2

    I am trying to block the visualization of a custom post, of type 'product', if it is assigned to certain values of the taxonomy 'product_cat'. Strictly speaking, I would like to block the visualization of a product if it falls under certain categorie

  • nginx server directive is not allowed hereJanuary 12

    I know there are dupes of this out there, but I can't seem to solve this in my situation. I'm following this article on setting up nginx as reverse proxy with apache. And I get this error: nginx: [emerg] "server" directive is not allowed here in

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.409 s.