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