How come CD doesn't work in my shell script?

How come cd doesn't work in my shell script?

  • SOLVED I'm trying to make a shell script on my Linux Amazon-EC2 server that will start my Minecraft server but the cd command says it can't find the directory or file when I try to change to the directory the server executable is in. Please note I have next to no experience with shell script of any kind. Does it have to with permissions in the folder this file is located in or the file itself? The file is named "startServer". #!/bin/bash cd /home/ec2-user/Minecraft java -Xmx2048M -Xms2048M -jar minecraft_server.jar nogui *I did not save it with a file extension. Should I? Does it need to be?

  • Answer:

    In order to make a script runnable you need to modify the permissions on the script so that it is executable. The command to change permissions on Linux or UNIX is http://en.wikipedia.org/wiki/Chmod chmod +x ./name_of_your_script Will grant the current user permission to execute the script. The #! at the start of your script indicates to the interactive shell that the script is to be interpreted by /bin/bash so you do not really need add an extention to the file name. However, it is a common convention to append .sh to shell scripts.

user1251172 at Super User Visit the source

Was this solution helpful to you?

Other answers

What exactly is the error message? My guess is that it is: cd: /Minecraft: No such file or directory This will happen if HOME is undefined, and ~ expands to the empty string.

William Pursell

The script will need execute permissions to be able to run it; to do this, cd to the directory is stored and use: chmod u+rwx startServer I don't think this is your problem though. Try using the full path to the minecraft_server.jar file rather than using cd: #!/bin/bash java -Xmx2048M -Xms2048M -jar /full/path/to/Minecraft/minecraft_server.jar nogui

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.