shell <<EOF

1、考虑下面的需求,在主shell执行命令,进入其他的命令,后面的输入,想作为命令的输入,而不是主shell的输入,怎么办?

2、使用<<EOF,告诉主shell,后续的输入,是其他命令或者子shell的输入,直到遇到EOF为止,再回到主shell。

3、这里的EOF只是分界符,使用其他的字符也可以。

4、比如cat,不使用EOF,如下:
[root@localhost ~]# cat >111.txt
abcd
1234

[root@localhost ~]# more 111.txt
abcd
1234
使用EOF
[root@localhost ~]# cat >111.txt<<EOF
> aaaa
> bbbb
> EOF
[root@localhost ~]# more 111.txt
aaaa
bbbb
5、mysql安装后之后,忘记密码,可使用说下面的脚本,如下:
/etc/init.d/mysqld stop

service mysqld start --skip-grant-tables
sleep 4
mysql -hlocalhost << EOF
update mysql.user set password=password('123456') where user ='root';
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
flush privileges;
EOF

/etc/init.d/mysqld restart

posted on 2015-05-30 17:38  Andy Niu  阅读(14236)  评论(0编辑  收藏  举报