How does ${path} work, in this tutorial

2019-07-25 12:29发布

问题:

I'm sure this is one of the dumbest problems asked on this site, but I am very new to linux, and a little out of my depths. I'm working off of this tutorial here and am stuck on the "add the path" and verify steps.

For this one the tutorial told me to use this:

export PATH=${PATH}:${DTITK_ROOT}/bin:${DTITK_ROOT}/utilities:${DTITK_ROOT}/scripts

I have already defined DTITK_ROOT, and have a few questions about the above instructions.

  1. Should the ${} be left around the DTITK_ROOT?
  2. My DTITK_ROOT is the full path (I think that's the right term) to the file I extracted the program to, should I change that?
  3. What do I write for ${PATH} in that case? I understand that I'm supposed to replace it with something, but I don't know what. Everything I've tried doesn't pass the verify step.

I'm sorry if it seems like a dumb or really simple question, but I don't even know any keywords to google in order to find how to get the answer.

回答1:

  1. Yes. This is how you access the path stored in DTITK_ROOT. This is called parameter expansion. You can read more about it here.

  2. No, don't change anything. Also, a more commonly used term is absolute path, in comparison to relative path. The absolute path is a path from the root directory, /. Relative path is a path from your current working directory. You can read more about paths in general and the difference between absolute and relative paths here.

  3. You don't replace it with anything. Once again, parameter expansion comes into play and this will be replaced with what is already stored in your path variable. So really all this command is doing is taking your path variable, adding some more paths to it, and then storing it back into your path variable. If you didn't know, the path variable contains paths to all executable files that you would like to execute without typing the full path. Here is a good discussion on path variables, along with other environment variables.



回答2:

1st command takes care of path

export DTITK_ROOT=mypathonSystem/dtitk

2nd command

export PATH=${PATH}:${DTITK_ROOT}/bin:${DTITK_ROOT}/utilities:${DTITK_ROOT}/scripts

I am not too sure but I think second command should run as is since you defined DDTITK_ROOT in first command ${PATH} is letting the system know where the resources can be found at

have you tried running first command, then running second command unmodified?



回答3:

  1. Should the ${} be left around the DTITK_ROOT?

Yes. In the case of the shell, it is not essential here because the / that follows the $DTITK_ROOT is enough to signal that we have reached the end of the variable name, but doing ${DTITK_ROOT} explicitly says that the variable name is DTITK_ROOT and not that plus whatever characters might be on the end of it. Other programs (such as make) which allow you to write shell commands to execute might not be so accommodating - make would think that $DTITK_ROOT would be the value of $D followed by the literal characters TITK_ROOT. So, it is a good practice to just get used to putting {} around shell variable names that are longer than a single character.

  1. My DTITK_ROOT is the full path to the file I extracted the program to, should I change that?

If you mean the full path to the directory that you extracted the program to, then that is what you should use. I am assuming that you have something like "export DTITK_ROOT=/Users/huiz/unix/dtitk" (per the example).

On thing you can do is to verify that the value of DTITK_ROOT is available by executing a "echo ${DTITK_ROOT}" to verify that it has the proper value.