我希望将我的MS-DOS .bat文件转换为等效的Linux .sh文件

时间:2015-05-05 16:18:05

标签: linux windows shell batch-file

基本上我必须让我的linux程序和我的MS-DOS做同样的事情。有人可以用指针和类似的东西来帮助吗? 目前所有的程序都是拉出一个菜单,用于基本的,高级的帐户创建和关闭 高级在atm中没有任何内容,而close也可以满足您的期望。 Basic然后问你:
全名

密码
然后将其全部保存在.log文件中(在检查已输入的用户名之后)以及确切的创建时间。例如:
Badja
约翰·多伊 123个
23/04/2015 15:07:32.61

@echo off
c:
:1
set curdir=%test%
echo Welcome to OP-SYS Account creation. Please choose which mode you would like to  continue in.
echo.
echo [1] Basic Account Creation
echo [2] Advanced Account Creation
echo [3] Exit
echo.

REM Menu choices
set /p cat=
if %cat%==1 (
goto 2
) else if %cat%==2 (
goto 3
) else if %cat%==3 (
goto 5
) else (
goto 4
)
:2
REM Basic account creation
echo Welcome to basic account creation.
REM user enters details

REM Username
echo Please Enter a Username
set /p username=
echo.
REM Real Name
echo Please enter your full name
set /p fullname=
echo.
REM Password
echo Please enter a password
set /p password=
echo.
REM Real name

REM Save to file
if exist %username%.log (
echo User name already exists, please enter a new user name to create an account, or return to the log in screen

goto 1
) else (
echo %username% >> %username%.log
echo %fullname% >> %username%.log
echo %password% >> %username%.log
echo %date% %time% >> %username%.log )
timeout /t 3 /nobreak > NUL
REM pause
goto end

:3
REM Advanced account creation
echo Welcome to advanced account creation.
echo This is not complete, please return to main menu.
Pause
goto 1

:4
REM Error
echo error
echo.
goto 1


:5
REM Exit
echo Goodbye.

goto end

:end
exit​

我知道有一些东西无法复制到linux,但我不知道从哪里开始,这是我的基础:

PS3='Please enter your choice: '
options=("cat 1" "cat 2" "end")
select opt in "${options[@]}"
do
    case $opt in
        "cat 1")
            echo "Basic"
            ;;
        "cat 2")
            echo "Advanced"
            ;;
        "end")
            break
            ;;
            *) echo invalid option;;
    esac
done

任何帮助都会让人惊叹!

2 个答案:

答案 0 :(得分:1)

function choice1 {

echo "Do stuff here to create an account"

}

function choice2 {

echo "Get the point?"

}

function choice3 {

exit

}

#### Main

echo "Welcome to OP-SYS Account creation. Please choose which mode you would like to continue in."
echo

echo "[1] Basic Account Creation
[2] Advanced Account Creation
[3] Exit"
echo

read CHOICE #### This loads your choice into a variable

eval choice"$CHOICE" ### This is evaluation awesomeness

答案 1 :(得分:0)

如果eval看起来很奇怪,你可以使用更传统的案例... esac语句来调用各种函数。我建议您在添加特殊功能之前让菜单循环并以您想要的方式转义。

clear
 echo "Welcome to OP-SYS Account creation. Please choose which mode you would like to continue in."
 echo

echo "[1] Basic Account Creation
[2] Advanced Account Creation
[3] Exit"
echo