Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 使用脚本shell创建多个文件_Linux_Bash - Fatal编程技术网

Linux 使用脚本shell创建多个文件

Linux 使用脚本shell创建多个文件,linux,bash,Linux,Bash,我需要使用shell脚本创建几个文件。到目前为止,我有这个和工程 #!/bin/bash var1="VALUE 1" var2="VALUE 2" ext="cfg" cat > file1 << EOF1 do some commands on "$var1" and/or "$var2" EOF1 #/bin/bash var1=“值1” var2=“值2” ext

我需要使用shell脚本创建几个文件。到目前为止,我有这个和工程

#!/bin/bash

var1="VALUE 1"
var2="VALUE 2"
ext="cfg"

cat > file1 << EOF1
do some commands on "$var1" 
and/or "$var2"
EOF1
#/bin/bash
var1=“值1”
var2=“值2”
ext=“cfg”

cat>file1是什么决定了要创建的文件名?这是你能循环通过的东西吗?从参数调用脚本

可以用变量替换file1

outfile=file1

cat > $outfile << EOF1
outfile=file1

cat>$outfile什么决定您将要创建的文件名?这是你能循环通过的东西吗?从参数调用脚本

可以用变量替换file1

outfile=file1

cat > $outfile << EOF1
outfile=file1

cat>$outfile通常,您会在计数器上循环:

for index in $(seq 50)
do
    touch "$index"
done
或在给定的名称列表上:

names=(first second third [...])
for name in "${names[@]}"
do
    touch "$name"
done

通常,您可以在计数器上循环:

for index in $(seq 50)
do
    touch "$index"
done
或在给定的名称列表上:

names=(first second third [...])
for name in "${names[@]}"
do
    touch "$name"
done

大家好,欢迎来到Stackoverflow。我注意到你回答了一个差不多有4年历史的问题,答案已经在另一个答案中给出了。如果您认为您的解决方案有一些好处,您能否解释一下它与现有解决方案相比有哪些优势?一般来说,我们不仅鼓励您将代码作为答案发布,还鼓励您对其进行解释。您好,欢迎来到Stackoverflow。我注意到你回答了一个差不多有4年历史的问题,答案已经在另一个答案中给出了。如果您认为您的解决方案有一些好处,您能否解释一下它与现有解决方案相比有哪些优势?一般来说,我们不仅鼓励将代码作为答案发布,还鼓励您对其进行解释。