How do I open a folder using a bash script running terminal

5,047

You need to use the -e option of xterm, and cd to go to the desired directory e.g. cd /foo/bar/. The tricky part is that the command will be run in a non-interactive session of your login shell, so if you want to keep a shell session open, tack the desired shell directly afterwards e.g. opening bash on that directory:

xterm -e 'cd /foo/bar/ && bash'

If your goal is to run an one-shot command, then just use the command directly (preferably use absolute path if unsure), no need to spawn a shell.

Share:
5,047

Related videos on Youtube

pst007x
Author by

pst007x

Updated on September 18, 2022

Comments

  • pst007x
    pst007x over 1 year

    I am trying to open a specific folder that is in a script:

        #!/bin/bash
        # Download youtube videos
        xterm -e /home/pst007x/Downloads/ youtube-dl https://youtu.be/-pjc1sWw6Dw
    

    What is happening the terminal is opening, but I am getting permission denied.

    Perhaps a stupid question, but how do I run a script to open a terminal in a specific folder?

    I have permission to access this folder.

    Thanks

    EDIT:

    This worked thanks:

    xterm -e 'cd /home/pst007x/Downloads/ && youtube-dl https://youtu.be/-pjc1sWw6Dw'
    
    • mikewhatever
      mikewhatever about 7 years
      It doesn't make much sense to "open a specific folder that is in a script". You'd rather cd to that folder, and then run commands.