Hello,

I am fairly new to scripting, I am interesting in writing a shell script which acts as a DOS command. I want to be able to utilize dos commands such as cd, dir, type, del, ren, and copy to do the same functions as the UNIX commands, cd, ls, cat, rm, mv, and cp. I want my script to loop continuously, so I may continue to type in dos commands until I type CTRL-C to exit.

I was thinking I can store the the dos commands in variables $command, $arg1 and $arg2 for example. I can then consider the command by a case statement which will then execute the appropriate UNIX command echoing the result.

So for example in my unix prompt I type:
del /F

the script should know I want to utilize rm -f

Can someone please help me set this first example up, and perhaps I can do the rest?

Recommended Answers

All 5 Replies

Why write a script? You can probably hack the environment up enough... :

#!/bin/bash
export PS1="C:\\w> "
alias dir="ls -l"
alias del="rm"
sk@sk:/tmp$ echo "" >> l
sk@sk:/tmp$ del l
-bash: del: command not found
sk@sk:/tmp$ . dos.sh
C:/tmp> del l
C:/tmp>

Yes I am familiar with Alias's but i'd like like to write this using a shell script. Any idea how to do this? :)

You're looking at rewriting a shell in a shell script? You're basically going to wrap all the commands to duplicate the environment. I don't see the point of what you're trying to do. Anyway you can do something like this but I have no idea how you're going to make it work:

#!/bin/bash

while true;
do
  echo -n "C:\> "
  read -a x
  echo "${x[0]} OUT"
  echo "${x[1]} OUT" #this assumes you have 2 arguments
  # do whatever
done

Example:

C:/tmp> ./dos.sh
C:\> ls -al
ls OUT
-al OUT
C:\> adsad asd
adsad OUT
asd OUT
C:\>
^C

$x is an array so you have the command and arguments. I guess you could wrap the commands and feed the arguments to the real commands replacing / with -.

Hey thanks for the help. I understand what your saying, and it makes sense.

Let me know if you need any additional assistance, and good luck!

Please mark this thread solved if I have answered your question.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.