Bash for loop - naming after n (which is user's input) -
this question has reply here:
how iterate on range of numbers defined variables in bash? 13 answersi looping on commands for in {1..n}
loop , want output files have n
extension.
for example:
in {1..2} cat file > ${i}_output done
however n
user's input:
echo 'please come in n' read number in {1.."$number"} commands > ${i}_output done
loop rolls on n
times - works fine, output looks {1..n}_output
.
how can name files in such loop?
edit
also tried
in {1.."$number"} k=`echo ${n} | tr -d '}' | cutting -d "." -f 3` commands > ${k}_output done
but it's not working.
use "c-style" for
-loop:
echo 'please come in n' read number ((i = 1; <= number; i++)) commands > ${i}_output done
note $
not required ahead of number
or i
in for
-loop header double-parentheses required.
bash
No comments:
Post a Comment