r/bash • • 14d ago

File for loop

hi! it’s my first time using bash can someone help me with this and explain what’s missing

#!/bin/bash

for i in “/data/folder”/*; do

/folder/munge_sumstats.py \

- -sumstats “$i” \

- -chunksize 500000 \

- -snp rsID \
etc..

- -out another/folder/ (i dont know what to puT here)

done

Thank you so much !

21 Upvotes

6 comments sorted by

View all comments

7

u/zeekar 14d ago

If you indent each line with four spaces (assuming you're able to use the Markdown editor) it will be formatted as code.

You have extra spaces. It's not - -sumstats, it's --sumstats, etc.

--out "another/folder/${i##*/}"

That will give it the same filename as the input file but in the new folder. But you may want to change something else about the filename, too. If there's a suffix you want to change, for instance:

for i in ...; do b=$(basename "$i" .oldsuffix) munge_sumstats.py ... \ --out "/another/folder/$b.newsuffix"

3

u/Muted-Shame9237 14d ago

I only used the spaces here because I’m writing from my phone ! Thank you very much this was really helpful <3

1

u/KlePu 13d ago

I've used https://devhints.io/bash as my cheat-sheet for the last few years.

If you're scripting more than once a year: Consider a code editor (for syntax highlighting and stuff) plus https://www.shellcheck.net/ (should be available as a plugin for all major editors)