The following is a simple script, named myscript, that I wrote in order to run a command.

dcm2nii $dcmpath/$dcmfile

Unfortunately, bash does not recognize the path in front of dcm2nii and I cannot run the last command in the file. I would be thankful if someone could let me know what I am missing. What would be the best way of customizing the path and file name which is the argument of a command?

  • "bash does not recognize the path in front of dcm2nii" - What path? dcm2nii is the first thing on the line, there's nothing in front of it.
    – phemmer
    May 19, 2014 at 3:27
  • I meant dcm2nii does not find the file with the full path: $dcmpath/$dcmfile although the file really exist. May 19, 2014 at 3:41

1 Answer 1

dcm2nii "$dcmpath/$dcmfile"

In the first line, you should use double quotes instead of single quotes. Single quotes prevent variables like $HOME from being expanded; they're interpreted literally. You can see the bash manual for details: http://www.gnu.org/software/bash/manual/bashref.html#Quoting

It doesn't matter in the second line; both single or double quotes will work fine.

It's also good idea to (double) quote the argument in the last line, in case the variables contain a space.

  • Thank you. It worked perfectly. What is the difference between defining the variable surrounded by single quotation and double quotation? May 19, 2014 at 3:27
  • @A2009 lk has explained that in the edit. May 19, 2014 at 5:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .