【问题标题】:what does ( if [ -z "$1" ] ) condition means in bash programming [duplicate]( if [ -z "$1" ] ) 条件在 bash 编程中意味着什么 [重复]
【发布时间】:2019-12-24 12:35:52
【问题描述】:

我有一个脚本如下:

#!/bin/bash

if [ -z "$1" ]; then
        echo "Missing output folder name"
        exit 1
fi

split -l 10000 --additional-suffix=.ordtmp orders.txt orders

for f in `ls *.ordtmp`; do
        if [ "$2" == "local" ]; then
                mv $f $1
        else
                hdfs dfs -copyFromLocal $f $1
                rm -f $f
        fi
        sleep 3
done

当我尝试运行它时,我得到错误:

(base) 01HW993798:ch06 tcssig$ ./splitAndSend.sh
Missing output folder name

文件是否需要在运行时提及输出文件夹?

【问题讨论】:

标签: bash macos


【解决方案1】:

$1 表示输入参数,-z 表示未定义或空

您正在测试在运行脚本时是否定义了脚本的输入参数

【讨论】:

    猜你喜欢
    • 2013-07-09
    • 2010-10-21
    • 2014-02-08
    • 2012-12-11
    • 2023-01-10
    • 2017-02-13
    • 1970-01-01
    • 1970-01-01
    • 2012-12-17
    相关资源
    最近更新 更多