linuxconcatenationcsh

String concatenation without spaces to make a file path


I am currently debugging some prewritten csh scripts to make them executable. I am running into some issues when it comes to combining two strings to create a complete file path.

I need to combine the file path:

rdir = ../picks/rec_files/REC_FILE_

with a dynamic file name:

mcs = 68320
nm = ${mcs}.txt (for example)

When trying to combine these two strings the output has large amounts of white space between the variables that I am unsure how to get rid of. Any help would be greatly appreciated.

What I've tried:

  1. file = ${rdir}${nm}

output = ../picks/rec_files/REC_FILE_ 68320.txt

  1. file = echo ${rdir}${nm}

output = ../picks/rec_files/REC_FILE_ 68320.txt

  1. file = "${rdir}${nm}"

output = ../picks/rec_files/REC_FILE_ 68320.txt

  1. file = echo `${rdir}${nm}`

output = ../picks/rec_files/REC_FILE_ 68320.txt

What I was expecting:
output = ../picks/rec_files/REC_FILE_68320.txt


Solution

  • Not sure what you are doing as the formatting is wrong, but you should do this

    bash% rdir='../picks/rec_files/REC_FILE_'
    bash% mcs='68320'; nm="${mcs}.txt"
    bash% file="$rdir/$nm"
    bash% echo "'$file'"
    '../picks/rec_files/REC_FILE_/68320.txt'
    

    and you can verify there's no extra spaces.