A variable modified inside a while loop is not remembered

后端 未结 8 2359
挽巷
挽巷 2020-11-21 05:06

In the following program, if I set the variable $foo to the value 1 inside the first if statement, it works in the sense that its value is remember

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-21 05:16

    Hmmm... I would almost swear that this worked for the original Bourne shell, but don't have access to a running copy just now to check.

    There is, however, a very trivial workaround to the problem.

    Change the first line of the script from:

    #!/bin/bash
    

    to

    #!/bin/ksh
    

    Et voila! A read at the end of a pipeline works just fine, assuming you have the Korn shell installed.

提交回复
热议问题