如何在Shell文件中更改pwd目录?

时间:2018-02-04 21:07:05

标签: linux bash shell

我有这个shell文件应该从不同的目录中提取数据,但是它试图用" $ pwd"从当前目录中提取文件。如何指定从中提取这些文件的文件夹,使其来自/ home / gnssb / Desktop / Data而不是/ home / gnssb / Desktop / Data / shell_scripts

    #!/bin/sh

    ORIG_DIR=$(pwd)
    basedir="../"

    year=2016;
    init_month=01;
    end_month=01;
    init_date=01;
    end_date=26;

    casesinp="${ORIG_DIR}/./cases-inp"

1 个答案:

答案 0 :(得分:0)

尝试添加cd

#!/bin/sh

ORIG_DIR=$(pwd)
basedir="../"

year=2016;
init_month=01;
end_month=01;
init_date=01;
end_date=26;

casesinp="${ORIG_DIR}/./cases-inp"

cd ${ORIG_DIR}/..
NEWPWD=$(pwd)

# NEWPWD would be level above shell-scripts now

# now, whatever commands following that gave you the wrong data before
# but on NEWPWD