LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 819|回复: 6

想编一个脚本改变hostname 我只是想学一下知识 这是例子

[复制链接]
发表于 2003-7-2 22:52:59 | 显示全部楼层 |阅读模式
想编一个脚本改变hostname
cat a
#!/bin/bash
echo "Are you want change the hastname? (y/n)"
read answer
if [ $answer = " y " ]
then
  echo "lease input the new hostname "
      read new
        hostname $new#这里错了
else
echo " pass any key to exit "
   ??#这里怎么作??
fi
发表于 2003-7-2 23:02:38 | 显示全部楼层
修改主机名可以直接编辑/etc/hosts文件!
如果你是为了练习,那么
1,切换到root身份,否则,hostname $new是出现错误的!
2,按任意键退出那行,可以这样作:
echo "...."
read#可有可无的
break
 楼主| 发表于 2003-7-2 23:43:24 | 显示全部楼层
不能用break
有错误提示。
发表于 2003-7-2 23:47:49 | 显示全部楼层
什么提示信息??
发表于 2003-7-3 06:49:03 | 显示全部楼层
how about exit(0). Not sure, Lot time did not touch this!
发表于 2003-7-3 10:45:10 | 显示全部楼层
我的/etc/hosts改了也没用.
后来用grep -R * /OpenLab | more
才找到真正的文件
发表于 2003-7-3 12:31:43 | 显示全部楼层
no loop or switch,no break! That's it.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表