简体   繁体   English

在bash中将文件名打印到脚本中

[英]print filenames into scripts in bash

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! 但是当我尝试用$ i打印其余字符串时,似乎不起作用!

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. 当我在$ i之前使用echo或反斜杠时,它也不起作用。

You need to keep format of printf on same line and keep $i outside single quotes: 您需要将printf格式保持在同一行上,并将$i保留在单引号之外:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM