0

I have an input directory (INPUT_DIRECTORY=${PWD}/INPUT) and a directory for output to save files into it a bash command (OUTPUT_DIRECTORY=${PWD}/Output) and a file (image-99.nii) need to be written in the OUTPUT_DIRECTORY. I have saved the file name with its basename into two variables (name=image-99.nii and FILENAME=image-99)

for FILE in ${INPUT_DIRECTORY}/*.nii; do
    name="echo ${FILE##*/}"
    FILENAME=$(echo "$name" | cut -f 1 -d '.')
    ....

How to concat OUTPUT_DIRECTORY and FILENAME in a way that the name becomes "image-99-N4.nii". I did the following command, but did not work

OUTPUTNAME="${OUTPUT_DIRECTORY}/${FILENAME}_N4.nii"

When I ~$ $OUTPUTNAME , I am getting an error bash: /echo: No such file or directory

2
  • You should add all relevant parts... we don't know from the question what is $OUTPUT_DIRECTORY.
    – pLumo
    Jun 20, 2018 at 10:18
  • Sidenote: Avoid using uppercase variable names unless they're environment variables. See this answer on Stack Overflow for details. You haven't overwritten any environment variables here, but if you used PATH, for example, that could easily break a script.
    – wjandrea
    Jun 20, 2018 at 16:17

1 Answer 1

2

The problem is not the line with OUTPUTNAME=, which is correct.

name="echo ${FILE##*/}"

should be

name="${FILE##*/}"

otherwise, echo will be part of the filename which is obviously not what you want.

But anyways. ~$ $OUTPUTNAME will only work, if the file is made executable. You might want echo "$OUTPUTNAME" or ls ....

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.