【问题标题】:BASH: How to copy the name of the file and insert it into the text using script?BASH:如何复制文件名并使用脚本将其插入文本中?
【发布时间】:2017-05-02 17:12:43
【问题描述】:

所以我需要创建很多文本文件。

每个文本文件命名为AAAAA.txt、BBBBB.txt、CCCCC.txt等。 在每个文本文件中,所有内容如下:

1.将“to-be-replaced”.txt复制到EXCLUSIVE文件夹中。

2.复制gs文件替换已有的gs文件。

3. .projectdata 也应该复制到正确的路径。

所以,我需要编写一个脚本,复制文件的名称(AAAAA、BBBBB 等),然后将其放在其内容中的“待替换”中。

我该怎么做?需要一些想法。

谢谢~~ MT32

【问题讨论】:

    标签: linux bash copy ubuntu-14.04 paste


    【解决方案1】:

    如果没有引用分隔符,请使用 HERE 文档来扩展变量:

    #!/bin/bash
    for char in {A..Z} ; do
        filename=$char$char$char$char$char.txt
        cat <<EOF > $filename
    1.Copy $filename into the folder EXCLUSIVE.
    
    2.Copy the gs file to replace the existing gs file.
    
    3.The .projectdata should also be copied to the correct path.
    
    EOF
    done
    

    【讨论】:

    • 我没有准确地说明我的问题,但我设法按照您的示例并使用字符串而不是 char,它工作得很好,除了一个问题:#!/bin/bash for string in cellanddungeon planesimulator FIFAsample ; do filename=$string cat"$filename".txt 1.将 access_$filename_200601.exe 复制到 EXCLUSIVE 文件夹中 2.复制 gs 文件以替换现有的 gs 文件。 3. .projectdata 也应该复制到正确的路径。结果文件名没问题,但第一行变成: 1. 将 access_.exe 复制到 EXCLUSIVE 文件夹中 有解决该问题的提示吗?
    • _ 是一个有效的变量名部分。使用${filename}_200601
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-08
    • 2013-10-02
    • 2013-12-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-19
    相关资源
    最近更新 更多