print filenames into scripts in bash

230 Views Asked by At

How do you print each name of a file from a directory into a string and make make new scripts?

to print each file name

for i in `ls new_manifest*`; do echo $i; done 

but when I try and print the rest of the string with $i like this is doesn't seem to work!

for i in `ls filenames*`; do
 printf
 '#!/bin/bash
 #$ -cwd
 #$ -j y
 #$ -S /bin/bash
 #$ -pe threaded 8

 $HOME/bin/program -vv -c $HOME/program.key -d $i --max 10' > $HOME/Scripts/$i.sh; done

also doesn't work when I use echo or a backslash before the $i.

1

There are 1 best solutions below

0
On BEST ANSWER

You need to keep format of printf on same line and keep $i outside single quotes:

for i in filenames*; do
 printf '#!/bin/bash
  #$ -cwd
  #$ -j y
  #$ -S /bin/bash
  #$ -pe threaded 8

  $HOME/bin/program -vv -c $HOME/program.key -d '"$i"' --max 10\n'
 done