Find the answer to your Linux question:
Results 1 to 3 of 3
First off I would like to say that I have googled my answer before coming here but I've had no luck(or maybe im blind :P) All I want is to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! Mo3u8se's Avatar
    Join Date
    Jan 2013
    Posts
    18

    Simple bash file.


    First off I would like to say that I have googled my answer before coming here but I've had no luck(or maybe im blind :P)
    All I want is to create a bash file that opens terminal, cd to a directory and runs a command. I've had no luck with getting this to work. Any help?
    Thanks.

  2. #2
    Linux User
    Join Date
    Dec 2011
    Location
    Turtle Island West
    Posts
    345
    There's a few options here.

    If the command is simple:
    Code:
    cd $DIR; xterm -e $COMMAND
    Or, if the command is complex or variable, make a shell script, SCRIPT.sh, and do chmod +x SCRIPT.sh, and put it somewhere in your $PATH:
    Code:
    #!/bin/sh
    
    cd $DIR
    $COMMAND $arg1 $arg2 $arg3
    SCRIPT.sh can be as complicated as you like.
    and then
    Code:
    xterm -e SCRIPT.sh
    Of course, change $DIR with the real directory, and $COMMAND with the real command.

    I use this all the time to create a menu of various config options, for example. Once the script terminates, the xterm goes away too. If you want to see the output of the command, put a 'read' at the end of the script so it will wait for a keypress before closing.

    Hope that helps.

  3. #3
    Just Joined! Mo3u8se's Avatar
    Join Date
    Jan 2013
    Posts
    18
    Thanks. That helped a lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •