apanimesh061 0 Junior Poster
function forcd
{ 
  len=`wc -c /home/mint/AP/file2.txt | cut -c1-2`
  cutcmd=`cut -c4-$len /home/mint/AP/file.txt`
  cd $cutcmd
}

newvar=`pwd`
clear

echo "root"$newvar">"
read cmd

until [ "$cmd" == "exit" ]; 
do
   
echo $cmd > /home/mint/AP/file.txt
cutcmd2=`cut -c1-3 /home/mint/AP/file.txt`

if [ "$cmd" == "dir" ]; then
   ls -l

elif [ "$cmd" == "dir /p" ]; then
     ls -l | more

elif [ "$cmd" == "cd .." ]; then
     cd ../

elif [ "$cutcmd2" == "cd " ]; then
      echo $cmd > /home/mint/AP/file2.txt
      forcd

elif [ "$cmd" == "cls" ]; then
     clear

else echo "ERROR-----> Invalid filename or command......!!!!!!"

fi

newvar=`pwd`
echo "root"$newvar">"
read cmd

done

This is small version of a DOS emulator
The command giving error is 'cd'

Suppose $cmd is "cd Documents"
Here,
/home/mint/AP/file.txt stores "cd Documents"
$cutcmd2 is "cd "

But, I have noticed that in '/home/mint/AP', another file.txt is created which is empty, and the function forcd and '$cutcmd2' use that file, and not the 'file.txt' that stores 'cd Documents', due to which condition "$cutcmd2" == "cd " is not satisfied, as the new file.txt is empty.....and this flags an error !!!!

Some people have also told me to use "read cmd opt"....and you'll have the command and options in two separate variables.....I dunno what to do ????
Please help...ASAP