Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.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
UNIX文件的顺序执行_Unix - Fatal编程技术网

UNIX文件的顺序执行

UNIX文件的顺序执行,unix,Unix,我想在unix中按顺序执行目录中的所有.sqls 假设目录名为/export/home/me 当我使用ls列出目录中的文件时 它表明 a.sql b.sql c.sql 现在,我需要编写一个shell脚本,该脚本将转到目录,循环遍历目录中的所有.sqls并按顺序执行它们。请建议假定顺序无关紧要: #!/bin/sh for file in folder/*.sql do cat $file #or whatever you want to do with your sql file

我想在unix中按顺序执行目录中的所有.sqls

假设目录名为/export/home/me 当我使用ls列出目录中的文件时 它表明

a.sql
b.sql
c.sql

现在,我需要编写一个shell脚本,该脚本将转到目录,循环遍历目录中的所有.sqls并按顺序执行它们。请建议假定顺序无关紧要:

#!/bin/sh

for file in folder/*.sql
do
    cat $file #or whatever you want to do with your sql file
done

如果按顺序,你的意思是按字母顺序排序,那么就这样做

#!/bin/sh

for i in `ls folder/*.sql | sort ` # I think the shell lists file sorted alphabetically by default
do
    mysql -u user_name -ppassword database_name < i
done
#/垃圾箱/垃圾箱
对于'ls folder/*.sql | sort`#中的i,我认为shell会列出默认按字母顺序排序的文件
做
mysql-u user\u name-ppassword数据库\u name
但是,在执行sql文件列表时,通常需要考虑顺序,例如,如果您的设计是,员工和部门,那么如果第一个sql文件创建员工表,第二个sql文件创建部门表的外键,即使在执行创建Departments表的第三个sql文件之前,您也会遇到麻烦


最好将数据库对象/数据的所有创建/插入语句按正确顺序放在一个SQL文件中。

您所说的顺序是什么意思?执行顺序重要吗?如何确定此顺序?我将在目录中创建单独的文件夹,顺序为我希望在directiry/export/home/me中执行.sqls.asket。。我创建了三个子目录ddl dml验证。现在每个子文件夹将包含n个.sqls,我需要循环遍历上述目录中的所有子目录,然后执行所有的.sqls。请建议谢谢…但是您所说的是至关重要的。因此,假设我在目录中为假设创建单独的文件夹,如DDL和dmls ETC。然后如何顺序执行每个文件夹中的所有.sqls。请再次感谢你之前的建议