The following is a simple script, named myscript, that I wrote in order to run a command.dcmpath='$HOME/Data'dcmfile='IM1'dcm2nii $dcmpath/$dcmfileUnfortunately, 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?
Problem in using user defined variable in a script
shell script;quoting
dcmpath=$HOME/Datadcmfile=IM1dcm2nii $dcmpath/$dcmfileIn 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#QuotingIt 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.