2

Here's a very simple, probably duplicate (sorry - I have tried searching) shell scripting question.

What's the correct syntax to set DATA_DIR as a subdirectory of WDM_DIR, in the script below? (Line 2.)

WDM_DIR='/Users/ap257/wdm/wdm'
DATA_DIR=$WDM_DIR+/wdm/pylons_data/getdata/
cd $DATA_DIR

The point is that people can change WDM_DIR to whatever path is right for their system, but DATA_DIR is always in the same place relative to it.

2 Answers 2

3

Here is the correct syntax

WDM_DIR=/Users/ap257/wdm/wdm
DATA_DIR=${WDM_DIR}/wdm/pylons_data/getdata/
cd -- "$DATA_DIR"

Well the syntax may vary a bit depending on what shell you are using.

Sign up to request clarification or add additional context in comments.

2 Comments

The last line should be cd -- "$DATA_DIR". The -- is in case $WDM_DIR starts with a - (not a problem if you require an absolute path). The quotes are in case $WDM_DIR contains a special character such as whitespace. Rule 1 of shell scripting: Always put double quotes around variable substitutions.
@Gilles Thank you for the inputs. I have updated my answer with your suggestions.
0

The easy way is:

DATA_DIR="${WDM_DIR}/wdm/pylons_data/getdata/"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.