Announcement

Collapse
No announcement yet.

cd command in a batch file

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    cd command in a batch file

    I find myself working alot in a directory deep in the system. Instead of typing
    cd /home/ant2ne/Folder1/Folder2/Folder3/Folder4/
    I would like to create a batch file so named tcd I just gotta type tcd and it executes the above line and have it put me in that directory to make adjustments and such. But executing the above line in the batch file doesn't actually change the directory. What gives?
    Registered Linux User: 450747<br />Registered Ubuntu User: 16269

    #2
    Re: cd command in a batch file

    Actually, it does change the directory as long as you are in the script.

    You should look at alias.

    Mark

    Comment


      #3
      Re: cd command in a batch file

      ok, alias is cool
      alias tcd=cd'cd /home/ant2ne/Folder1/Folder2/Folder3/Folder4/'
      this allows me to type tcd in terminal and it changes the directory. But if I try to use tcd in the batch file it fails.

      Basically I want a short word command (batch file) to change what ever directory is current to the Folder4 directory. Then, still in the batch, I want it to execute a command or two before dumping me back to a command prompt. When I'm dumped back to the prompt I want to be in Folder4. Any advice? I'm pretty new at this batch file creation.

      Registered Linux User: 450747<br />Registered Ubuntu User: 16269

      Comment


        #4
        Re: cd command in a batch file

        http://tldp.org/LDP/Bash-Beginners-G...ect_03_02.html

        Comment


          #5
          Re: cd command in a batch file

          Interesting and informative link. But I don't see how it applies to my particular problem of changing the directory and leaving me there. Could you maybe put it into context.

          An additional question. In my batch file I want it to execute a few different programs. But it doesn't want to execute the next one, until the first one finishes and closes. How do I get it to go to the next step without completing the first step?
          Registered Linux User: 450747<br />Registered Ubuntu User: 16269

          Comment


            #6
            Re: cd command in a batch file

            Originally posted by Ant2ne
            Interesting and informative link. But I don't see how it applies to my particular problem of changing the directory and leaving me there. Could you maybe put it into context.
            If you execute a script it is run in a subshell and doesn't affect the current environment. You can run
            Code:
            source /your/script
            to execute it in the current environment. Create a script test.sh
            Code:
            exit 0
            and run it as a) ./test.sh and b) source ./test.sh to see the difference - be warned that the second call will log you out however...

            Originally posted by Ant2ne
            An additional question. In my batch file I want it to execute a few different programs. But it doesn't want to execute the next one, until the first one finishes and closes. How do I get it to go to the next step without completing the first step?
            You could execute it in the background:
            Code:
            /some/program -with -parameters &
            (note the & in the end of the line)

            Comment

            Working...
            X