I'm trying to run my .sh file but when I try to execute it it doesn't work.
I did echo '#!/bin/bash' > cadetkpgm.sh in order for the .sh file to be executable but when I use ./cadetkpgm.sh or bash cadetkpgm.sh to run the file t it doesn't work... any ideas?
Asked
Active
Viewed 159 times
-2
Olli
- 8,811
- 1
- 34
- 40
Kerven Cadet
- 13
- 1
-
What's the error message? It probably tells you exactly what the problem is ;-) – janos Feb 25 '14 at 19:04
-
./cadetkpgm2.sh: line 1: cadetkpgm2.sh: command not found – Kerven Cadet Feb 25 '14 at 19:05
-
that's he error that comes up... – Kerven Cadet Feb 25 '14 at 19:05
-
It looks like the line 1 of `cadetkpgm2.sh` is `cadetkpgm2.sh`. Check what's inside the file using `cat cadetkpgm2.sh`, because I think it's not what you think it is. After you fix the content of the file, `bash cadetkpgm2.sh` will run it. You can make it executable with `chmod u+x cadetkpgm2.sh`. – janos Feb 25 '14 at 19:09
-
Also, the she-bang, '#! /bin/bash' should go at the top – Panther Feb 25 '14 at 19:11
-
i placed the shebang on the top by useing the echo '#!/bin/bash' > cadetkpgm.sh – Kerven Cadet Feb 25 '14 at 19:14
-
I am little bit confused. What is your file name `cadetkpgm.sh`or `cadetkpgm2.sh`? – g_p Feb 25 '14 at 19:24
-
the second one is – Kerven Cadet Feb 25 '14 at 19:26
-
And what is the purpose of this first one. Pls provide a little bit more detail. – g_p Feb 25 '14 at 19:36
-
1`echo '#!/bin/bash' > cadetkpgm.sh` would overwrite your file to just contain `#!/bin/bash` – Dan Feb 25 '14 at 20:28
-
could you write the contents of your script? – Braiam Feb 25 '14 at 20:35
1 Answers
1
#!/bin/bash does not turn your shell script into an executable.
It only makes sure that it will be interpreted by bash for which you give the location - once you have made it executable by chmod u+x SCRIPTNAME.
Let me explain again: cadetkpgm.sh is not a command, unless you have made it executable.
Klaus-Dieter Warzecha
- 2,720
- 1
- 22
- 27
-
im required to place that into the .sh file. when I try to run it it gives me this error: ./cadetkpgm2.sh: line 1: cadetkpgm2.sh: command not found. – Kerven Cadet Feb 25 '14 at 19:10
-
1