How to convert following dos batch code to unix shell:-

echo Database username and password will be taken from file....
for /f "tokens=1* delims==" %%a in ( do (
if "%%a"=="username" set dbuser=%%b
if "%%a"=="password" set dbpwd=%%b
if "%%a"=="url" set dburl=%%b
echo UserName is:=%dbuser%
echo PassWord is:=%dbpwd%
echo URL is:=%dburl%
if not %errorlevel%==0 goto ON_FILE_READ_ERROR


It is hard to answer your question without knowing what type of shell you need. What will the script be used for and what will it interact with?
For example a file is sometimes used to set variables for a specific php session.


 * configuration file

// Database connection info
define("CONN_HOST", "localhost", TRUE);
define("CONN_PORT", 3306, TRUE);
define("CONN_USER", "servicedb", TRUE);
define("CONN_PASS", "nokidding", TRUE);
define("CONN_DB", "Service", TRUE);

What you are trying to do is very easy in any of a hundred different ways depending on the type of script needed. Can you tell us a little more about what you are doing or typing to do?

What is the format of the (linux?) version of the file? Can you specify it or is it already in some format?

What is the actual goal here: Do you want to let the user log in to the database from the command line? Do you want to use PHP as rch1231 suggests? Some other language? If you can control the format of the properties file, then you might have it be syntactically correct for your programming language and just do some equivalent of #include (syntax depends on the language, of course)

This article has been dead for over six months. Start a new discussion instead.