Question

01) I am trying to use the && operator in a for loop as shown below in the script. However this does not seem to work. I was not able to see the error generated in the terminal window, since it closes as soon as it runs in to an error. Could someone please tell me what I'm doing wrong?

#!/bin/bash

cd ~/Documents/DTI/

#subj and subj1 contain folders which are located in the DTI directory
subj="ARN MT"
subj1="ARNpre1 ARNpre2"

for [[s in $subj] && [s1 in $subj1]]

02) And as you can see in my "subj1", the first two entries start with the letters ARN which means that they are sub directories of ARN(located in a different place.Not in ARN main directory). So I also want to run a command in which, if subj1 contains subj then it must perform a certain command.For this purpose I wrote the following,

if [[ ${s1} == *"${s}"* ]];then

would this be the right way to do such operation?

I would greatly appreciate any help.

Thank you in advance.

Was it helpful?

Solution

I think by for [[s in $subj] && [s1 in $subj1]] you mean this:

for s in $subj; do
  for s1 in $subj1; do
    # do something
  done
done

By nesting the for loops you'll loop through every possible combination of s and s1, which sounds like what you're trying to do in part 1 of your question.

However, I can't make sense of what you're talking about in part 2, so I can't help you there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top