1

I am trying to create directory using mkdir inside sh file, when I do that the directory is created, but then when trying to do something to it, I get the message "rm: cannot remove '/testFolder': No such file or directory", but it is there...

What am i doing wrong?

this is my sh file

#!/bin/sh
mkdir -p /testFolder
wget https://launcher.mojang.com/v1/objects/bb2b6b1aefcd70dfd1892149ac3a215f6c636b07/server.jar -O /testFolder/server.jar
echo "cd /testFolder\njava -Xmx1024M -Xms1024M -jar server.jar nogui" >> /testFolder/startMc.sh

then i call the file sudo sh test.sh

9
  • 2
    Are you using Ubuntu? Why are you trying to create testFolder in /, not in ~?
    – Pilot6
    Jan 24, 2020 at 12:17
  • I am using ubuntu server 19 well i could try that, did not think of that
    – Niroh
    Jan 24, 2020 at 12:18
  • 1
    There is no ubuntu server 19 release. Remove / in front of testFolder and all should work.
    – Pilot6
    Jan 24, 2020 at 12:19
  • Still does not work..
    – Niroh
    Jan 24, 2020 at 12:23
  • 1
    What doesn't work? Does mkdir testFolder work? Are there any errors. Most likely you don't run the script. Please edit your question and add all steps you do.
    – Pilot6
    Jan 24, 2020 at 12:26

1 Answer 1

0

The new line \n is not being interpreted by the echo command try adding the -e argument to echo:

#!/bin/sh
mkdir -p /testFolder
wget https://launcher.mojang.com/v1/objects/bb2b6b1aefcd70dfd1892149ac3a215f6c636b07/server.jar -O /testFolder/server.jar
echo -e "cd /testFolder\njava -Xmx1024M -Xms1024M -jar server.jar nogui" >> /testFolder/startMc.shenter code here
1
  • All works great now, not sure why it did'n work before. It is making new line without -e thanks :)
    – Niroh
    Jan 24, 2020 at 16:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .