-4

I have written a script abc.sh and saved it in a place called generallstuff. I navigate to this folder with:

cd ~ /generallstuff

when i try to run the script with:

chmod 755 abc.sh

i get the error "no such file or directory"

But the script is in this place, why is this. Previously i had no problem running scripts

Levon
  • 11,384
  • 4
  • 45
  • 41

2 Answers2

7

cd ~ /generallstuff should be cd ~/generallstuff, otherwise you will change into your home directory instead.

Chris Down
  • 125,559
  • 25
  • 270
  • 266
6

Where/When exactly does the error message show up?

A couple of things to check:

(1) The chmod command makes the script only executable, it does not run it. chmod +x abc.sh will make your script executable.

Aside: I much prefer the "human readable" version of the chmod command to the one using octal notation. So for instance:

chmod u+x file means change file for user to executable (or just +x, the user is implied by default).

You can specify group, others in place of u, or combinations. In place of x you can use w, r etc, again in combinations if wanted

Use + to add, - to take away attributes.

See the chmod man page for more information.

(2) Do you have the appropriate shell incantation at the top of your shell file? e.g.,

 #!/bin/bash

(or whichever shell you want)

(3) How are you running it? This way should work:

./abc.sh

(4) Note: Your cd command has a space (' ') between the ~ and /generallstuff .. hopefully that's just a typo in the posting; otherwise, the command will fail and you won't change directories!

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Levon
  • 11,384
  • 4
  • 45
  • 41
  • On chmod: it depends on the initial permissions of the file. Generally a user created file has: -rw-rw-r--. +x will change this to -rwxrwxr-x = 775. 755 is usually seen on non-Linux systems, where the group name is different from user name. Use the stat command to compare numeric and human-readable formats. – lgarzo Jun 15 '12 at 08:12