开发者

bash script to create and print string into files from list

I'm on opensus 11.3 and I am looking for a bash script to do the following:

  1. Create directories and rename them from a .txt list, each new name is a new line 开发者_运维技巧on that .txt

  2. Copy file.php from to each new directory, and rename all file.php files in those directories to a specific name.

  3. Print a "/< php ? >/" string into the first line in each of those files.

I assume the best and fastest to accomplish this will be in bash, if you have another idea I will be happy to listen.


Edit:: This is the version modified according to OP's last comment:

#/bin/bash

while read name; do
    # prepare file to copy into new dirs
    echo "\<php \$city= \"$name\" ?\>" > tempfile
    cat file.php >> tempfile

    # create dir & copy modified file.php into it
    mkdir -p "$name"
    cp tempfile "$name"/filename.php
done < names.txt
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜