菜单脚本怎么写
A. BAT 新建开始菜单目录、快捷方式脚本
@echo off
set shortCutPath=C:\Documents and Settings\All Users\“开始”菜单\程序\机器猫
set shortCutName=cat
set shortCutSource=D:\Program Files\machine cat\cat.exe
md "%shortCutPath%"
echo Dim WshShell,Shortcut>>tmp.vbs
echo Dim path,fso>>tmp.vbs
echo path="%shortCutSource%">>tmp.vbs
echo Set fso=CreateObject("Scripting.FileSystemObject")>>tmp.vbs
echo Set WshShell=WScript.CreateObject("WScript.Shell")>>tmp.vbs
echo Set Shortcut=WshShell.CreateShortCut("%shortCutPath%\%shortCutName%.lnk")>>tmp.vbs
echo Shortcut.TargetPath=path>>tmp.vbs
echo Shortcut.Save>>tmp.vbs
"%SystemRoot%\System32\WScript.exe" tmp.vbs
@del /f /s /q tmp.vbs
以上保存为.bat文件即可。
另外,第2、3、4行的
set shortCutPath.........
set shortCutName........
set shortCutSource............
这三行等分别存入的是:
快捷方式路径(不含文件名)、快捷方式名字、源文件路径(含文件名),
只要修改对应的内容,就可以更改创建快捷方式的位置,文件名,以及指向的源文件。
B. 结合一些简单的LINUX命令编写一个脚本实现简单的菜单功能,掌握IFwhile,for等条件和循环语句使用
供参考:(一),实现菜单操作;
(二),实现新增用户,删除用户,修改用户名,修改用户密码。
while :
do
cat << EOF
================================================================= Welcome to use the shellscripts 1.Add user
2.Delete user
3.Modify username
4.Modify password
q.Quit=================================================================
EOF read -p "Please enter your choice: " CHOICE
case $CHOICE in
1) read -p "Please enter username: " USERNAME
useradd $USERNAME && echo "User create ok!"
;;
2) read -p "Please enter username: " USERNAME
userdel -r $USERNAME && echo "User delete ok"
;;
3)
read -p "Please enter olsername: " USERNAME1 read -p "Please enter newusername: " USERNAME2
usermod -l $USERNAME2 $USERNAME1 && echo "Username modify ok"
;;
4)
read -p "Please enter username: " USERNAME
passwd $USERNAME
;;
q|Q)
clear
exit 0
;;
*)
clear
;;
esac
done