1

I'm trying to get the basenames of some files and combine them in an output file within a loop. I'm trying to assign the basenames to variables 'x' and 'y' but keep getting the error "x: command not found". Why does bash think 'x' and 'y' are commands and what is the best way to get both file names (but not paths or extensions) in the output file? Thanks for any help!

for i in ~/SOSP/pops/*.txt
do 
    x = $(basename $i)
    for j in ~/SOSP/pops/*.txt
    do 
        y = $(basename $j)
        vcftools --vcf ~/SOSP/sosp.vcf --weir-fst-pop $i --weir-fst-pop $j --out ~/SOSP/fst_pairs/${x}_vs_${y}.txt
    done
done
mklement0
  • 382,024
  • 64
  • 607
  • 775
JAGriff
  • 11
  • 1
  • 5
    There mustn't be whitespace around `=` in POSIX-like shell variable assignments; [shellcheck.net](http://shellcheck.net) would catch such errors. – mklement0 May 05 '16 at 04:33

1 Answers1

4

don't put spaces around the =:

doesn't work:

x = $(basename $i)
y = $(basename $j)

works:

x=$(basename $i)
y=$(basename $j)
webb
  • 4,180
  • 1
  • 17
  • 26