如何在shell脚本的while循环内使用if-else语句?

时间:2018-07-23 14:40:44

标签: bash shell sh

比较CSV中的两个变量时遇到一些问题

这是我的代码

package skyxplore.dataaccess.gamedata.base;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;

import org.apache.commons.io.FilenameUtils;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import skyxplore.dataaccess.gamedata.entity.abstractentity.GeneralDescription;

@Slf4j
public abstract class AbstractGameDataService<V> extends HashMap<String, V> {
    public static final String BASE_DIR = "src/main/resources/data/gamedata/";

    private static final ObjectMapper objectMapper = new ObjectMapper();
    private static final JsonFileFilter jsonFilter = new JsonFileFilter();

    private final String source;

    public AbstractGameDataService(String source) {
        this.source = BASE_DIR + source;
    }

    protected void loadFiles(Class<V> clazz) {
        File root = new File(source);
        if (!root.exists()) {
            throw new IllegalStateException("Source directory does not exists. Path: " + root.getAbsolutePath());
        }
        if (!root.isDirectory()) {
            throw new IllegalArgumentException("Source must be a directory. Path: " + root.getAbsolutePath());
        }
        File[] files = root.listFiles(jsonFilter);
        for (File file : files) {
            try {
                String key = FilenameUtils.removeExtension(file.getName());
                V content = objectMapper.readValue(file, clazz);
                if (content instanceof GeneralDescription) {
                    GeneralDescription d = (GeneralDescription) content;
                    log.info("Loaded element. Key: {}, Value: {}", key, content);
                    put(d.getId(), content);
                } else {
                    throw new RuntimeException(source + " cannot be loaded. Unknown data type.");
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public abstract void init();
}

我的文件中有些字段具有#!/bin/bash exec < /path/to/file/PARAM.csv || exit 1 read header # read (and ignore) the first line while IFS=, read table column; do if [[ $column = "NULL" ]]; then echo "empty" else echo $column fi done 值,但是比较不起作用,它总是打印"NULL"

以下是我的CSV中的一些示例:

$column

0 个答案:

没有答案