0

I have two lists of variables that are equal to each other and I am trying to make a bash script in order to put both of these subject variable name files into one folder:

Here is an example of the list of variables:

az100 ms200 #first subject
az101 ma600 #second subject

where I want az100 == ms200 == ${SUBJECT}

for SUBJECT in az100
do
    dicoms=${SUBJECT}/dicoms
    rsync -aP /path/${SUBJECT}/ "$dicoms"
done

I know that I could manually do this, but I was wondering what the most elegant and efficient way to make two variables equal to each other in a for loop?

here is an example of what I have tried:

for SUBJECT in az100 az200 az300

        rsync -aP /path/${SUBJECT}/* /path/${SUBJECT}/dicoms

    for SUBJ_MR_CODE in mz100 mz200 mz300
        do
        rsync -aP /path/${SUB_MR_CODE}/* /path/${SUBJECT}/dicoms
    
        done
        done

However, this seems like a risky approach, and I want to make sure there are error codes if az100 doesn't equal mz100 for example.

5
  • 1
    It's not clear what you mean. Can you show what you "can do manually" so we can understand what you're trying to achieve?
    – choroba
    May 18, 2022 at 8:43
  • I'm also not sure what you mean by "lists of veriables"
    – Ted Lyngmo
    May 18, 2022 at 8:47
  • Thank you! sorry I am new at this! I have subject 1. Subject 1 has two different code names: az100 and ms200. I have two directories that have files in them that I want to copy and do the same things to: az100/file ms200/file. I want to be able to move all these files in both directories to a common folder. I want to make the SUBJECT variable equal to both az100 and ms200 and make sure that I am never accidentally coupling az100 with a different ms variable e.g. ms300.
    – Maria
    May 18, 2022 at 9:39
  • I have a very long list of subject names where each row has two subject codes that are equal to first, second, third, subjects.
    – Maria
    May 18, 2022 at 9:41
  • How to make two variables equal to each other: var1="$var2". You can put that assignment inside a for loop. I do not understand the rest of your question.
    – Nic3500
    May 18, 2022 at 22:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.