0

I have this shell file which is supposed to extract data from a different directory, but it tries to extract files from current directory with "$pwd". How can I specify a folder to extract these files from, such that it comes from /home/gnssb/Desktop/Data instead of /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"
user unknown
  • 35,537
  • 11
  • 75
  • 121
D Patel
  • 11
  • 2
  • Replace `$(pwd)` with `"$PWD/.."`? – Cyrus Feb 04 '18 at 21:11
  • where (what path) your script resides? – danilo Feb 04 '18 at 21:12
  • 2
    Nothing in this script extracts anything at all. Please ensure that what you're showing us follows the [mcve] definition -- it should be the shortest possible code *that actually reproduces a specific problem described in the question when run*. A program that just assigns a bunch of variables is not a program that extracts files into the wrong directory. – Charles Duffy Feb 04 '18 at 21:17
  • That said, you might find [Bash variable substitution vs basename and dirname](https://stackoverflow.com/questions/22401091/bash-variable-substitution-vs-dirname-and-basename) interesting, insofar as this question might be asking for the functionality that `dirname` provides. – Charles Duffy Feb 04 '18 at 21:21

1 Answers1

0

try adding a 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
yftse
  • 183
  • 6