Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a text-based game, Colossal Cave Adventure, that I would like to launch with a shell script instead of opening the terminal and typing "cd ~/Desktop/CCA" and "./Adventure". The code i am trying to use is this:

#! /bin/bash
gnome-terminal -e 'cd ~/Desktop/CCA/; ./Adventure'

and the message i receive is this:

There was an error creating the child process for this terminal
Failed to execute child process "cd" (No such file or directory)

with options to change profile preferences or relaunch the process. I have also tried using the absolute path instead of ~/, and all of my file names are correctly spelled and point to the right place. What is wrong?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

the cd is not a command, it's a shell tool. you should use this:

#! /bin/bash
gnome-terminal --working-directory=/home/username/Desktop/CCA/ -e './Adventure'
share|improve this answer
    
Thank you, I was not aware that cd wasn't a command. –  Giaphage47 May 28 at 6:14

The error

Failed to execute child process "cd" (No such file or directory)

arises because cd is one of the SHELL BUILTIN COMMANDS and not an executable that you physically find on your Hard Disk.

To run it or the others built-in commands in you script you need to pass all the line to a bash invocation

 gnome-terminal -e '/bin/bash -c "cd ~/Desktop/CCA/; ./Adventure" '   

If there are no other internal command that you have to execute you can set the working directory for the gnome terminal, as just answered here:

gnome-terminal --working-directory=/home/username/Desktop/CCA/ -e './Adventure'

Ad nauseam: there are some alternatives:

If you are just in a terminal you can either do

  • an alias like
    alias Star_My_Game="cd ~/Desktop/CCA; ./Adventure "
    and put it in your .bashrc or in ~/.bash_aliases so that you will be able to run with the single command Start_My_Game in each shell you will be (It's more cosy to choose a simpler/short name than Start_My_Game...)

  • or a script that you can make executable (chmod u+x MYscript) and put in your path (tipically ~/bin is a good candidate).

I suppose you can put a link on your desktop that execute the terminal and modify the starting behaviour. From gnome help

  1. Select Edit ▸ Profile Preferences ▸ Title and Command.

  2. Check Run a custom command instead of my shell.

  3. In the text box, type the command or the desired shell.

  4. The command will be passed to the terminal exactly as you write it, including any arguments that you specify. Environment variables will be inherited from the terminal as it is a child process of the terminal.

    Open a new Terminal tab or window to see how the custom shell or command executes

share|improve this answer
    
But the point was to launch from a shell script, and not have to open a terminal window. –  Giaphage47 May 28 at 6:16
    
If you want to launch from a script is enough an alias (more cosy) or a script in your ~/bin directory, without to launch a new terminal –  Hastur May 28 at 6:19
    
Answer updated just in case you need again: it's possible to pass cd but you need to pass it to bash. Give it a check :) – –  Hastur May 28 at 7:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.