Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.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
如何从单独的输入行(从文件或stdin)格式化bash命令行_Bash - Fatal编程技术网

如何从单独的输入行(从文件或stdin)格式化bash命令行

如何从单独的输入行(从文件或stdin)格式化bash命令行,bash,Bash,我正在尝试编写一个脚本来批量更新一组数据库表。我在一个文件中有一个列表(但我也可以从stdin获得它),我正在尝试构造altertable命令。我有以下几点 while read table; do echo "ALTER TABLE $table ENGINE=Aria"; done < tables 而不是 ALTER TABLE mydatabase.mytableone ENGINE=Aria; ... 如我所料。我做错了什么?最后,我将echo更改为mysql-uroot-p

我正在尝试编写一个脚本来批量更新一组数据库表。我在一个文件中有一个列表(但我也可以从stdin获得它),我正在尝试构造
altertable
命令。我有以下几点

while read table; do echo "ALTER TABLE $table ENGINE=Aria"; done < tables
而不是

ALTER TABLE mydatabase.mytableone ENGINE=Aria;
...

如我所料。我做错了什么?最后,我将
echo
更改为
mysql-uroot-ppassword-e“ALTER TABLE$TABLE ENGINE=Aria;”

文件
tables
有DOS
\r\n
行结尾。这将导致
$table
\r
回车结束,打印时将光标移回行首


您需要。

Cat命令将处理您的新行saperators

请尝试以下代码:

$ cat tables | while read table; do echo "ALTER TABLE $table ENGINE=Aria"; done

cat file | while
while
没有什么不同,除了。John你试过吗?是的。这也不例外。cat不转换行尾或带回车符。
$ cat tables | while read table; do echo "ALTER TABLE $table ENGINE=Aria"; done