Linux Bash Shell学习(十三):流程控制——while/util

  本文也即《Learning the bash Shell》3rd Edition的第五章Flow Control之读书笔记之五,但我们将不限于此。flow control是任何编程语言中很常用的部分,也包括了while和util,他们在高级编程语言中也常见。在这里,我们将继续学习他们。

  while和util的语法一样,如下:

whileutil condition ; do
    statements ...
done

  和if一样,condition可以有一系列的statements组成,值是最后的statment的exit status。while和until条件判度刚好想法,while检查条件,当为真的时候执行,而until坚持条件,当为假的时候执行。和C不一样,util是一开始就坚持条件,而不是在每次循环的最后。如果将判度加上"!",while和util实际没有什么区别,但是until在下面的情况有点意思:

until command ; do
    statements ...
done

  执行statements,直至command正确运行。

until cp $1 $2; do
    echo 'Attempt to copy failed. waiting...'
    sleep 5
done

  例如上面的例子,每隔5秒尝试copy命令,直至copy成功,当然也可以用while !cp $1 $2; do ...的方式。
  令我们将bash shell脚本加上后缀名sh,这样在gedit中编译可以有不同颜色显示,比较方便。

  相关链接: 我的Linux操作相关文章

 

SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/opt/spark/spark-2.4.0-bin-hadoop2.7/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/opt/Hadoop/hadoop-2.7.2/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/opt/hbase-1.2.6/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory] 25/03/21 15:56:07 WARN Utils: Your hostname, master resolves to a loopback address: 127.0.0.1; using 192.168.180.130 instead (on interface ens33) 25/03/21 15:56:07 WARN Utils: Set SPARK_LOCAL_IP if you need to bind to another address 25/03/21 15:56:08 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable Setting default log level to "WARN". To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel). 25/03/21 15:56:09 WARN Utils: Service 'SparkUI' could not bind on port 4040. Attempting port 4041. 25/03/21 15:56:12 WARN FileStreamSink: Error while looking for metadata directory. Traceback (most recent call last): File "/home/abz/PycharmProjects/untitled1/2024.10.22.test.py", line 6, in <module> df = spark.read.csv("传媒综合.csv", header=True, inferSchema=True, sep="|", encoding='utf-8') File "/opt/spark/spark-2.4.0-bin-hadoop2.7/python/pyspark/sql/readwriter.py", line 472, in csv return self._df(self._jreader.csv(self._spark._sc._jvm.PythonUtils.toSeq(path))) File "/opt/spark/spark-2.4.0-bin-hadoop2.7/python/lib/py4j-0.10.7-src.zip/py4j/java_gateway.py", line 1257, in __call__ File "/opt/spark/spark-2.4.0-bin-hadoop2.7/python/pyspark/sql/utils.py", line 63, in deco return f(*a, **kw) File "/opt/spark/spark-2.4.0-bin-hadoop2.7/python/lib/py4j-0
最新发布
03-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值